Cloud-config Reference

Node OS images build using the Elemental Toolkit are expected to be initialized and configured by using yip. Yip is a small utility to apply a set of actions and configurations to the system described with yaml files. Yip is integrated and consumed as a library within the elemental client binary (see elemental run-stage --help). Yip groups the configurations and actions to apply in arbitrary stages, for instance the elemental run-stage network command call would only apply defined actions and configuration for the stage named network. Note from Yip perspective stages can be run at any time as they are simply grouping a set of actions under an arbitrary name.

Elemental Toolkit integrates five predefined stages into the OS boot process.

  1. rootfs: this stage runs on early boot inside the init ram disk, just after mounting the root device (typically at /sysroot). This stage can be used to define first-boot steps like expanding or creating persistent partitions. Ephemeral and persistent paths are typically defined at this stage. Executed as part of the initrd-root-fs.target.

  2. initramfs: this stage runs inside the init ram disk too, but on a later stage just before switching root. This stage runs in a chrooted environment to the actual root device. This stage is handy to set some system parameters that might be relevant to systemd after switching root. For instance, additional systemd unit files could be added here before the systemd from the actual root is executed. Executed as part of the initrd.target.

  3. fs: this stage is the first one executed after switching root and it is executed as part of the sysinit.target which runs once all all local filesystems and mountpoints defined in fstab are mounted and ready.

  4. network: this stage is executed as part of the multi-user.target and after the network-online.target is reached. This stage can be used to run actions and configurations that require network connectivity. For instance this stage is used to run the very first node registration and and installation from a live ISO.

  5. boot: this stage is executed as part of the multi-user.target and before the getty.target. This is the default stage to run cloud-config data provided using the supported cloud-init syntax. See cloud-init compatibility section.

By default, elemental reads the yaml configuration files from the following paths in order: /system/oem, /oem and /usr/local/cloud-config.

Cloud-config reference - 图1note

In contrast to similar projects such as Cloud Init, Yip does not keep records or caches of executed stages and steps, all stages and its associated configuration is executed at every boot.

Configuration syntax

Yip has its own syntax, it essentially requires to define stages and a list of steps for each stage. Steps are executed in order and each step can be a combination different action types (e.g run commands, create files, set hostname, etc.).

Consider the following example:

  1. stages:
  2. boot:
  3. - files:
  4. - path: /tmp/script.sh
  5. content: |
  6. #!/bin/sh
  7. echo "test"
  8. permissions: 0777
  9. owner: 1000
  10. group: 100
  11. - commands:
  12. - /tmp/script.sh

In the above exaple there is one boot stage including two steps, one to create an executable script file and a second one that actually runs the script.

Yip also supports *.before and *.after suffix modifiers to any given stage. For instance, running the network stage results into running first network.before stages found in config files and then network and finally network.after.

See the full reference of applicable keys in steps documented in yip project itself.

Compatibility with Cloud Init format

A subset of the official cloud-config spec is implemented by yip. More specific the supported cloud-init keys are: users, ssh_authorized_keys, runcmd, hostname and write_files are implemented.

If a yaml file starts with #cloud-config it is parsed as a standard cloud-init, associated it to the yip boot stage. For example:

  1. #cloud-config
  2. users:
  3. - name: "bar"
  4. passwd: "foo"
  5. groups: "users"
  6. homedir: "/home/foo"
  7. shell: "/bin/bash"
  8. ssh_authorized_keys:
  9. - faaapploo
  10. # Assigns these keys to the first user in users or root if there
  11. # is none
  12. ssh_authorized_keys:
  13. - asdd
  14. # Run these commands once the system has fully booted
  15. runcmd:
  16. - foo
  17. # Write arbitrary files
  18. write_files:
  19. - encoding: b64
  20. content: CiMgVGhpcyBmaWxlIGNvbnRyb2xzIHRoZSBzdGF0ZSBvZiBTRUxpbnV4
  21. path: /foo/bar
  22. permissions: "0644"
  23. owner: "bar"

In Elemental all kubernetes resources including a cloud-config field assume cloud-init syntax. This includes resources such as MachineRegistration or SeedImage.

Below is an example of the above configuration embedded in a MachineRegistration resource.

MachineRegistration example

  1. apiVersion: elemental.cattle.io/v1beta1
  2. kind: MachineRegistration
  3. metadata:
  4. name: my-nodes
  5. namespace: fleet-default
  6. spec:
  7. config:
  8. cloud-config:
  9. users:
  10. - name: "bar"
  11. passwd: "foo"
  12. groups: "users"
  13. homedir: "/home/foo"
  14. shell: "/bin/bash"
  15. ssh_authorized_keys:
  16. - faaapploo
  17. ssh_authorized_keys:
  18. - asdd
  19. runcmd:
  20. - foo
  21. write_files:
  22. - encoding: b64
  23. content: CiMgVGhpcyBmaWxlIGNvbnRyb2xzIHRoZSBzdGF0ZSBvZiBTRUxpbnV4
  24. path: /foo/bar
  25. permissions: "0644"
  26. owner: "bar"
  27. elemental:
  28. install:
  29. reboot: true
  30. device: /dev/sda
  31. debug: true
  32. machineName: my-machine
  33. machineInventoryLabels:
  34. element: fire