Using Cloud-Init with Proxmox for Automated VM Deployment
Introduction
Deploying virtual machines manually in Proxmox can be time-consuming, especially for repetitive setups. Cloud-Init is a powerful tool that automates VM provisioning, allowing you to pre-configure users, network settings, and packages on first boot. This guide will show you how to integrate Cloud-Init with Proxmox for fast and efficient VM deployment.
Step 1: Download a Cloud-Init Ready Image
- SSH into your Proxmox Host
-
Open a terminal and connect to your Proxmox server:
ssh root@your-proxmox-ip
- Download a Cloud-Init Image
-
Use Ubuntu or Debian Cloud-Init images:
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img -O ubuntu-cloudimg.img
- Convert the Image to Proxmox Format
-
Convert and move the image to Proxmox storage:
qm create 9000 --name ubuntu-cloud --memory 2048 --core 2 --net0 virtio,bridge=vmbr0
qm importdisk 9000 ubuntu-cloudimg.img local-lvm
qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9000-disk-0
Step 2: Configure Cloud-Init in Proxmox
- Attach a Cloud-Init Drive
-
Run the following command:
qm set 9000 --ide2 local-lvm:cloudinit
qm set 9000 --boot c --bootdisk scsi0
- Set Up a Default User
-
Define a default user and SSH key for access:
qm set 9000 --ciuser ubuntu --sshkeys ~/.ssh/id_rsa.pub
- Configure Network Settings
-
Set a static IP or DHCP:
qm set 9000 --ipconfig0 ip=dhcp
Step 3: Create a VM Template
- Convert the VM into a Template
-
Once configured, turn the VM into a reusable template:
qm template 9000
- Deploy VMs from the Template
-
Clone the template to create a new VM:
qm clone 9000 100 --name new-vm --full true --storage local-lvm
-
Start the VM:
qm start 100
Step 4: Customize Cloud-Init Configuration
- Modify Cloud-Init User Data
-
Edit user-data settings:
nano /etc/pve/qemu-server/100.conf
-
Add custom configurations, such as:
ciuser: ubuntu
cipassword: mysecurepassword
hostname: my-cloud-vm
- Regenerate Cloud-Init Configuration
-
Apply changes by regenerating Cloud-Init data:
qm cloudinit dump 100 user
Conclusion
You’ve successfully set up Cloud-Init with Proxmox for automated VM deployment. This allows for rapid provisioning with preconfigured settings, saving time and effort in managing virtual machines.