Important:
Windows does not support this function.
VM cloud-init is used to automatically configure newly-created virtual machines. IEC uses the cloudInitNoCloud storage in the KubeVirt module, which can imitate the traditional cloud-init process but does not require the support of a cloud service provider and can be directly embedded the User Data and Network Data of the virtual machine.
Prerequisites
To use the cloud-init, create a virtual machine by using an image that has cloud-init enabled and has been set up. Therefore, cloud-init can be executed normally during first startup. For images that are not set up, do the following to complete the settings:
- Create a virtual machine (e.g. ubuntu-22.04-server-cloudimg-amd64.img)
- Set up cloud-config using the following user data.
- Start the VM and connect to the VM by using VNC. Log in to the VM with the username test. The password is test, too.
- Check if the cloud-config has been set up successfully:
- Check if the /var/boot_time.txt file has been created
- Check if network data has been set
User Data
User data is the most common cloud-init data source which is used to early initialization of virtual machines including setting up user accounts, installing software, starting services, etc.
Here is an example of cloud-init cloud-config userdata:
#cloud-config
hostname: test-den-vm
password: init
users:
- default
- name: test
gecos: Foo Bar
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
lock_passwd: false
chpasswd:
list: |
test:test
expire: False
bootcmd:
- echo "This is run at boot time" > /var/boot_time.txt#cloud-config: Specify the YAML format used for user data.users: Define and modify system users.lock_passwd: Allows users to log in with password.ssh_authorized_keys: If you have set an SSH Key in the configurations of a virtual machine, it will automatically be written.chpasswd: Change user password.bootcmd: Execute commands when the system boots.package_updateandpackage_upgrade: update and upgrade system software packages.runcmd: Execute the command.write_files: Create or modify files.hostname: Set the system host name.
Network data
Network data is used to specify network configuration, such as IP address, gateway, DNS settings, etc.
Here is an example of cloud-init cloud-config network data:
network:
version: 2
ethernets:
ens1:
dhcp4: true
enp3s0:
addresses:
- 172.27.112.133/20
routes:
- to: default
via: 172.27.127.254
nameservers:
addresses:
- 192.168.99.16
- 192.168.99.14
dhcp4: falseFor more details about using cloud-init package, you may find more useful information and resources at the following resources: