第 2 章 Introduction to cloud-init
The cloud-init utility automates the initialization and configuration of virtual machines (VM), also known as instances, during the first boot. You can configure cloud-init to perform tasks such as:
- Configuring a hostname, network interfaces, and user accounts
- Installing packages on an instance
- Running scripts
- Modifying default virtual machine (VM) actions
Before you begin, make sure to complete the following step:
- You have created a Red Hat account.
cloud-init is available for various types of RHEL images as follows:
-
A KVM
qcow2guest image comes preinstalled withcloud-init. After you launch the instance, thecloud-initutility is automatically enabled. You can use KVM guest images from the Red Hat Customer Portal with Red Hat Virtualization, Red Hat OpenStack Platform (RHOSP), and Red Hat OpenShift Virtualization. -
If you download a Red Hat ISO image from the Red Hat Customer Portal to create a custom guest image, you need to install the
cloud-initpackage on that customized guest image. If you use an image from a certified cloud service provider (CCSP), such as Amazon Web Services (AWS), Google Cloud, or Microsoft Azure, you can use RHEL image builder to create the image. RHEL image builder customizes images for specific cloud providers. The following image formats come with
cloud-initpreinstalled:- Amazon Machine Image (AMI)
- Virtual Hard Drive (VHD)
- QEMU copy-on-write (QCOW2)
For details about the RHEL image builder, see Installing RHEL image builder.
Most cloud platforms support cloud-init, but configuration procedures and supported options vary.
Otherwise, you can configure cloud-init for the NoCloud environment. By using NoCloud, you can manage cloud instances for both a local configuration (without network access) and configurations fetched from a remote server. Additionally, you can create a VM template by configuring cloud-init on one VM. By using this template, you can create additional VMs or clusters of VMs.
2.1. Overview of the cloud-init configuration 复制链接链接已复制到粘贴板!
The cloud-init utility uses YAML-formatted configuration files to apply user-defined tasks to instances. When an instance boots, the cloud-init service initiates and executes the instructions from the YAML file. These tasks may complete during the first boot or on subsequent boots of the VM, depending on the configuration.
To define the specific tasks, configure the /etc/cloud/cloud.cfg file and add directives under the /etc/cloud/cloud.cfg.d/ directory.
The
cloud.cfgfile includes directives for various system configurations, such as user access, authentication, and system information. This file also includes default and optional modules forcloud-init. The default module groups are as follows:-
cloud_init_modules -
cloud_config_modules -
cloud_final_modules
-
-
You can include additional directives for
cloud-initin thecloud.cfg.ddirectory. -
While adding directives to the
cloud.cfg.ddirectory, add them to a custom file named*.cfg, and always include#cloud-configat the top of the file.
For details, refer to an example file of cloud.cfg. See an example of cloud.cfg file.