Cloud-Init
Table of Contents
1. Basics
1.1. What?
- go-to tool for automating the initial setup of virtual machines (VMs) on cloud instances.
- prevalent in Linux distributions.
1.2. How?
- when a VM first boots up on a cloud instance, a configuration process is run (cloud-config)
- this doesn't run on reboots but only on the first initialization
1.3. Where?
- works with AWS, Azure, Google Cloud Platform, OpenStack, and more.
- also functions in private cloud setups and even for bare-metal installations.
1.4. Why?
- Automation: Saves time and effort in manual VM configuration, especially when managing multiple instances.
- Consistency: Provides a standardized way to set up your VMs across different cloud environments.
- Scalability: easier to launch and configure numerous VMs on demand.
2. Specifics
2.1. General Tasks
Cloud-init handles common initial configuration tasks for VMs:
- Setting the Hostname: Ensuring your VM has a unique name.
- Network Configuration: Setting up network interfaces for communication.
- Installing Packages: Installing essential software and updates.
- Managing Users and SSH Keys: Creating users and authorizing SSH keys for secure login.
- Executing Custom Scripts: Running scripts to perform any specific setup tasks you need.
2.2. Working Mechanism
The four stages of cloud-init in chronological order of execution:
2.2.1. Init Local
- runs as early as possible in order to allow cloud-init to generate
network configuration and activate networking.
- run as soon as the root filesystem is mounted read-write.
- Cloud-init will go and search for any local data source objects that may allow it to obtain metadata to configure the system.
- If any information is received cloud-init will proceed to setup networking devices, including bridges, bonds, vlans, etc.
2.2.2. Init
- runs after networking is up and searches for any network data sources to find metadata for the system.
- allows for custom storage configurations and expanding disk volumes to occur very early on.
- also make any changes requested to make to the block devices as well as setup file systems.
- the user-data for the system is obtained for use during the next stage.
2.2.3. Modules Config
- follows immediately after the previous one to guaranteed networking and begins running the cloud-init config modules.
- SSH keys are imported
- apt or yum is configured
- time related services are configured
2.2.4. Modules Final
- runs at the very end of the boot process.
- involves package install and configuration via user-scripts.
- Puppet and chef tools are setup and configured, and finally the final message module is run.