Creating automatic deployment of linux images on Proxmox
Cloud-init is a service that sets up your VM instance with the wanted configuration and software ready to use. The service starts at boot and uses the metadata provided by the cloud provider or the direct user. It does so by executing scripts, most commonly from the cloud-config file.
My task was to accomplish the automatic setup of a linux VM on any random allocated node with the provided data by the API my company was using.
For that I was needing a cloud image of the linux distribution that I was setting up and I've just ran the following commands on the proxmox node after downloading the OS image to add it like a template that Proxmox could use to setup automatically any new VM.
virt-customize -a ubuntu-image-cloud.img --install qemu-guest-agent
This command would install the package named "qemu-guest-agent" in order to let the hypervisor communicate with the VM and transmit the data to the hypervisor.
qm create 2222 --name "ubuntu-cloudinit-template" --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0
This command would create the VM with 2 allocated cores and 2 GB of RAM on the Proxmox node.
qm importdisk 2222 ubuntu-image-cloud.img local-zfs
This command will import the downloaded and modified OS image to the VM with the ID 2222 we've just created on the disk named "local-zfs".
qm set 2222 --scsihw virtio-scsi-pci --scsi0 local-zfs:vm-2222-disk-0
This command will allocate the imported disk to the VM.
qm set 2222 --boot c --bootdisk scsi0
This command will make the disk I've just allocated bootable as the first boot option for the VM.
qm set 2222 --ide2 local-zfs:cloudinit
This command will add my cloud-init drive to the VM so I can control its configuration.
qm set 2222 --serial0 socket --vga serial0
This command will add a serial KVM console to the VM.
qm set 2222 --agent enabled=1
This command will enable the VM's agent.
qm template 2222
This command will turn my freshly created VM into a template.
Then I can just clone the VM template with ID 2222 to any new VM and it will let us configure the VM's information via the cloud-init drive I've added.