ruk·si

cloud-init

Updated at 2017-12-11 00:56

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:

  1. Injects cloud-init.target to multi-user.target to download multiple .service files.
  2. Runs cloud-init-local.service before networking is setup.
  • Ultimately calls /usr/bin/cloud-init init --local
  1. Runs cloud-init.service after networking setup.
  • Ultimately calls /usr/bin/cloud-init init
  1. Runs cloud-configure.service to configure modules.
  2. 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:

  1. Create /etc/cloud/cloud-init.disabled file.
  2. Or add KERNEL_CMDLINE="cloud-init=disabled" environment variable.

Sources