cloud-init
Most cloud-based virtual machines configure themselves with cloud-init. cloud-init was original an Ubuntu project to support AWS EC2 ecosystem. Configuration is required so instances can start from a single image and them customize themselves.
As a normal developer, you rarely need to work with cloud-init But it's good to know it's there.
cloud-init is not a replacement for init, it's an augmentation. The naming can be misleading.
Execution flow:
- Injects
cloud-init.targettomulti-user.targetto download multiple.servicefiles. - Runs
cloud-init-local.servicebefore networking is setup.
- Ultimately calls
/usr/bin/cloud-init init --local
- Runs
cloud-init.serviceafter networking setup.
- Ultimately calls
/usr/bin/cloud-init init
- Runs
cloud-configure.serviceto configure modules. - Runs
cloud-final.serviceto finalize modules.
/etc/cloud/cloud.cfg is the place for shared configuration between instances. Instance specific configuration is in /run/cloud/cloud.cfg or defined with CLOUD_CFG environmental variable. Both of these are YAML files.
What developers usually interact with is user data / vendor data. Cloud service provider creates a metadata HTTP endpoint where to fetch the data you defined when creating the instance. User data is commonly limited to 16KB but can download additional scripts to be executed.
User data content types:
#include = download these URLs and execute
#cloud-init = replace the /etc/cloud/cloud.cfg with this
#cloud-config = define additional cloud-init directives
#!/bin/bash = run as bash script
How to disable cloud-init for local development:
- Create
/etc/cloud/cloud-init.disabledfile. - Or add
KERNEL_CMDLINE="cloud-init=disabled"environment variable.
Sources
- cloud-init Documentation
- Linux Magazine November 2017, Core Technology - cloud-init