Cloud-init drive template in Proxmox
Cloud-init drive template in Proxmox automates the initial configuration of virtual machines.
What is Cloud-init Drive?
In Proxmox, the “cloud-init drive” is a virtual disk that you attach to a virtual machine or container. This virtual disk tells the machine how to set itself up when it initially starts running. It’s convenient because you can include details such as the machine’s name, internet connectivity settings, and even the software it should install right from the outset. This facilitates the process of setting up new machines, particularly when managing a large number of them, by streamlining and expediting the configuration process.
Why use cloud-init drive?
When you start using proxmox, majority of vm will be based of linux server which take a lot of process to create a VM and not to mention, repeating in the same process. So enabling cloud-init drive attaching to the storage drive will give you access to speed up VM generating much faster by cloning from the template which I’ll show you later on.
Proxmox VM GUI process
Creating a Virtual Machine
- General: Begin by creating a VM with a high “VM ID” number and a unique VM name.
- OS: Choose “Do not use any media” as we will attach the cloud-init drive later on. Maintain the “type” and “version” as default.
- System: Leave all settings as default, but ensure to check the box for “Qemu agent”.
- Disks: Remove any existing attached disks since we’ll be attaching the cloud-init drive later.
- CPU: Configure with limited resources since this will serve as a template.
- Memory: Again, limit the configuration as this will be used as a template.
- Network: Keep all settings as default.
- Confirm: Verify that all settings are aligned correctly, but do not check the box for “start with created”.
Adding the Cloud-init Drive
- After creating the VM, navigate to the “hardware” section to add the cloud-init drive.
- Select the desired storage location where you intend to store your VM data.
- Proceed to configure settings in Cloud-init such as user, password, SSH, etc.
Command Line Process in Terminal
- Begin by accessing the terminal and SSH into Proxmox.
- Next, acquire the cloud image from the website. In this example, we’re using Ubuntu Server.
- Follow the provided code block containing all the necessary commands to complete the process.
1
2
3
4
5
6
7
8
9
10
11
1. wget https://cloud-images.ubuntu.com/minimal/releases/jammy/release/ubuntu-22.04-minimal-cloudimg-amd64.img
2. qm set [--node number--] --serial0 socket --vga serial0
3. mv [Downloaded iso] --new iso [change the iso to].qcow2
4. qemu-img resize new-iso.qcow2 20G
5. qm importdisk [--node number--] ubuntu-22.04.qcow2 --storage [storage]
Create SSH Key on the Host Machine
To access the VM from your host machine without entering the password each time, you need to create an SSH key and save the public key in the cloud-init tab.
- Generate an SSH key by using the command and following the prompts.
1
ssh-keygen
- Next, copy the key from the file path where it is stored.
1
2
cd ~/.ssh
cat [your-key].pub # copy the key on your clipboard
- Return to Proxmox, navigate to the cloud-init tab under template, and paste the key into the SSH option.
Final Steps to Finish the Process
- In the hardware tab, select the drive, click “edit”, and then add to activate the drive.
- Proceed to the Options tab where you need to adjust the “Boot Order”.
- After ensuring that everything is set up correctly, convert the VM into a template.
- As a final step, clone from the template to verify that everything is functioning correctly.
Next steps to speed up the process.
Creating a cloud-init template offers the advantage of speeding up the process through automation. You can leverage this by developing an Ansible playbook that outlines the tasks for VM creation in Proxmox. Typically, this playbook encompasses tasks for VM creation, attaching the cloud-init drive, and applying any additional configurations you deem necessary.
Conclusion
Certainly, cloud-init isn’t a requirement for creating a virtual machine in proxmox, but it can significantly expedite the process and eliminate redundancy. Once you’ve followed the outlined process, you can proceed to create VMs either by cloning the template or by utilizing an automation route through an Ansible playbook. This approach streamlines the VM creation process and enhances efficiency.