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.target
tomulti-user.target
to download multiple.service
files. - Runs
cloud-init-local.service
before networking is setup.
- Ultimately calls
/usr/bin/cloud-init init --local
- Runs
cloud-init.service
after networking setup.
- Ultimately calls
/usr/bin/cloud-init init
- Runs
cloud-configure.service
to configure modules. - Runs
cloud-final.service
to 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.disabled
file. - Or add
KERNEL_CMDLINE="cloud-init=disabled"
environment variable.
Sources
- cloud-init Documentation
- Linux Magazine November 2017, Core Technology - cloud-init