{"id":13778,"date":"2022-05-11T03:02:56","date_gmt":"2022-05-11T01:02:56","guid":{"rendered":"https:\/\/contabo.com\/blog\/?p=13778"},"modified":"2023-08-07T03:48:09","modified_gmt":"2023-08-07T01:48:09","slug":"what-is-cloud-init","status":"publish","type":"post","link":"https:\/\/contabo.com\/blog\/what-is-cloud-init\/","title":{"rendered":"What is Cloud-Init and Why is it so Cool?"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/05\/blog-head_1200x630_cloud-init.jpg\" alt=\"Cloud-Init Header Picture\" class=\"wp-image-13792\" srcset=\"https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/05\/blog-head_1200x630_cloud-init.jpg 1200w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/05\/blog-head_1200x630_cloud-init-600x315.jpg 600w, https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/05\/blog-head_1200x630_cloud-init-768x403.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p>Setting up new cloud instances can be very time-consuming, especially if you are dealing with a lot of configurations and software. With cloud-init, you\u2019ll never have to worry about this ever again.<\/p>\n\n\n\n<p>Cloud-init is a software developed for cloud server instances that will set up the server automatically using the provided metadata. This metadata describes how your server should look like, e.g. which packages should be installed and commands that\u2019ll be executed on init.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-video\">Video<\/h2>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"ast-oembed-container \" style=\"height: 100%;\"><iframe loading=\"lazy\" title=\"What is Cloud-Init and How does it work?\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/l8cuQ6WakSU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/div>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-does-it-work\">How does it work?<\/h2>\n\n\n\n<p>Cloud-init will set up your cloud instance as described in a config file. If you\u2019re familiar with Docker, the cloud-init config is like the Dockerfile and the cloud instance is the Container. The config file is written in YAML and you can use it as a blueprint for new cloud instances. Here is an example of a cloud.cfg:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#cloud-config\n\nusers:\n\n    - default\n\ndisable_root: true\n\npreserve_hostname: false\n\napt_preserve_sources_list: true\n\nsystem_info:\n\n   distro: debian\n\n   default_user:\n\n      name: debian\n\n      lock_passwd: True\n\n      gecos: Debian\n\n      groups: &#91;adm, audio, cdrom, dialout, dip, floppy, netdev, plugdev, sudo, video]\n\n      sudo: &#91;\"ALL=(ALL) NOPASSWD:ALL\"]\n\n      shell: \/bin\/bash\n\n   paths:\n\n      cloud_dir: \/var\/lib\/cloud\/\n\n      templates_dir: \/etc\/cloud\/templates\/\n\n      upstart_dir: \/etc\/init\/\n\n   package_mirrors:\n\n     - arches: &#91;default]\n\n       failsafe:\n\n         primary: http:\/\/deb.debian.org\/debian\n\n         security: http:\/\/security.debian.org\/\n\n   ssh_svcname: ssh\n\nbootcmd:\n\n  - echo \u201cHello world!\u201d &gt; \/home\/hello.txt\n\npackages:\n\n  - vim\n\n  - git\n\n  - htop<\/code><\/pre>\n\n\n\n<p>This config will install the packages vim, git, and htop and also create a new file \/home\/hello.txt with \u201cHello world!\u201d. Also, it\u2019ll create a default user as described in system_info and disable the root user.<\/p>\n\n\n\n<p>There are many <a href=\"https:\/\/cloudinit.readthedocs.io\/en\/latest\/topics\/modules.html\" rel=\"nofollow\">modules<\/a> you can use to configure your server exactly how you need it. For example, use the <a href=\"https:\/\/cloudinit.readthedocs.io\/en\/latest\/topics\/modules.html#bootcmd\" rel=\"nofollow\">bootcmd<\/a> module to run custom commands early in the boot process. Or create custom user accounts and assign them groups using the <a href=\"https:\/\/cloudinit.readthedocs.io\/en\/latest\/topics\/modules.html#users-and-groups\" rel=\"nofollow\">users and groups<\/a> module.<\/p>\n\n\n\n<p>You can find more <a href=\"https:\/\/cloudinit.readthedocs.io\/en\/latest\/topics\/examples.html\" rel=\"nofollow\">examples of cloud-init configs here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-why-cloud-init-when-i-have-docker\">Why Cloud-Init when I have Docker?<\/h2>\n\n\n\n<p>When talking about replicating environments, you might think about <a href=\"https:\/\/www.docker.com\/\" rel=\"nofollow\">Docker<\/a> instead. But the good news is, you don\u2019t actually have to choose between the two. Because in order to use Docker, you need to have Docker installed and configured on the machine and that\u2019s what cloud-init is for. When setting up a new machine, <a href=\"https:\/\/jameskiefer.com\/posts\/manage-a-docker-container-on-an-ubuntu-vm-using-just-cloud-init\/\" rel=\"nofollow\">cloud-init can install and set up Docker<\/a> for you and then Docker can be used to run your software.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cloud-init-at-contabo\">Cloud-Init at Contabo<\/h2>\n\n\n\n<p>Contabo customers can use cloud-init with <a href=\"https:\/\/contabo.com\/en\/vps\/\" target=\"_blank\" rel=\"noreferrer noopener\">Cloud VPS<\/a> and <a href=\"https:\/\/contabo.com\/en\/vds\/\" target=\"_blank\" rel=\"noreferrer noopener\">VDS<\/a>. The best way to do that is to use the <a href=\"https:\/\/api.contabo.com\/\">Contabo API<\/a>. With the API, it\u2019s possible to pass your cloud-init config directly when you order the VPS. After your VPS is ready, your configuration is already applied and the server is ready. It is also possible to enable cloud-init on existing server and reinstall it using cloud-init.<\/p>\n\n\n\n<p>Head over to the <a href=\"https:\/\/api.contabo.com\/#operation\/createInstance\">API documentation<\/a> to read more about setting up a cloud instance using the Contabo REST API.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-full-power-of-cloud-init\">The Full Power of Cloud-Init<\/h2>\n\n\n\n<p>Cloud-init can be used way beyond just setting up the cloud instance with specific users and packages. For example, you can set up a whole LAMP stack application like WordPress using only this method. With the Contabo API, this means a new WordPress installation is just one API call away.<\/p>\n\n\n\n<p>This also means that creating multiple machines with the same configuration and software isn\u2019t a big deal anymore. Create a cloud-init config once, use it all the time. There is no need to manually configure all of the instances anymore.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-disaster-recovery\">Disaster Recovery<\/h3>\n\n\n\n<p>Setting up new machines may also be required in the event of a disaster, as you will need more instances to handle the workload if others fail. This is another use case of cloud-init, as in such times it is more than important that new instances with all the required configuration and software are quickly up and running.<\/p>\n\n\n\n<p>Recreating a specific environment is no big deal anymore when you have cloud-init, and this is very important in cases where you have to replicate a machine quickly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-clusters-and-kubernetes\">Clusters and Kubernetes<\/h3>\n\n\n\n<p>In a cluster, you have multiple nodes (machines) to perform specific tasks and quickly respond to changing workloads. But even then, you will get to the point where your current server configuration just isn\u2019t capable of handling all the tasks and maybe you\u2019ll get there much faster than expected, so it\u2019s important to act quickly. Again, that\u2019s where cloud-init comes to the rescue by setting up the new nodes automatically according to a central configuration so no manual configuration is needed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The process of setting up new server instances can be very annoying and time-consuming. While Docker can be used to replicate a certain software environment, Cloud-Init can be used to replicate the whole server with all of its programs and configurations.<\/p>\n","protected":false},"author":57,"featured_media":13792,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[],"ppma_author":[1525],"class_list":["post-13778","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"uagb_featured_image_src":{"full":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/05\/blog-head_1200x630_cloud-init.jpg",1200,630,false],"thumbnail":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/05\/blog-head_1200x630_cloud-init-150x150.jpg",150,150,true],"medium":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/05\/blog-head_1200x630_cloud-init-600x315.jpg",600,315,true],"medium_large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/05\/blog-head_1200x630_cloud-init-768x403.jpg",768,403,true],"large":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/05\/blog-head_1200x630_cloud-init.jpg",1200,630,false],"1536x1536":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/05\/blog-head_1200x630_cloud-init.jpg",1200,630,false],"2048x2048":["https:\/\/contabo.com\/blog\/wp-content\/uploads\/2022\/05\/blog-head_1200x630_cloud-init.jpg",1200,630,false]},"uagb_author_info":{"display_name":"Linus Benkner","author_link":"https:\/\/contabo.com\/blog\/author\/linus\/"},"uagb_comment_info":0,"uagb_excerpt":"The process of setting up new server instances can be very annoying and time-consuming. While Docker can be used to replicate a certain software environment, Cloud-Init can be used to replicate the whole server with all of its programs and configurations.","authors":[{"term_id":1525,"user_id":57,"is_guest":0,"slug":"linus","display_name":"Linus Benkner","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/396885b0c71ca364e267b5804deaef19e48538c136b5287377b0d481091abd10?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/13778","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/users\/57"}],"replies":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/comments?post=13778"}],"version-history":[{"count":2,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/13778\/revisions"}],"predecessor-version":[{"id":24002,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/13778\/revisions\/24002"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media\/13792"}],"wp:attachment":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media?parent=13778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/categories?post=13778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/tags?post=13778"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=13778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}