Proxmox Automation

Some scripts I use to set up and destroy clusters or just build a set ot VM's. I use the cloud-images for a ready-to-run VM with minimal intervention. #proxmox #automation #script

Proxmox Automation
Photo by Andrea De Santis / Unsplash

Some scripts I use to set up and destroy clusters or just build a set ot VM's. I use the cloud-images for a ready-to-run VM with minimal intervention.

myTemplatebuilder.sh

A quick way of creating Ubuntu 22.04 Server or Minimal Server based:

  • Downloads the cloud-image (it's a .qcow2 file but with .img extension)
  • creates a template
  • a set of VM's
  • option install libguestfs-tools
  • add Qemu-Guest-Agent to the image
  • a set of my favorite tools are also in the script, just edit

Ubuntu Cloud Images are pre-installed disk images that have been customized by Ubuntu engineering to run on cloud-platforms. They are official Ubuntu images that have been customized by Canonical to run on public clouds that provide Ubuntu Certified Images, Openstack, LXD and more. Cloud-init is included.

We can use them on Proxmox.

Basic set up in the script is a VM to be used as a Template (RAM 1024 and 1 core) with QEMU-Guest-Agent (or not - not recommended). Create a Template and from it 1-3-n VM's. This is a speedy way to start using a Proxmox Cluster.

Make it what you need by editing the script:

qm create 9000 --memory 1024 --core 1 --name ubuntu-mini --net0 virtio,bridge=vmbr0
Important note - you need to add a serial console, to be able to see console output!
qm set 9000 --serial0 socket --vga serial0

VM ID: 9000 so its clearly above any VM/CT's we are going to run (100-900).
The cloned VM's will be 5001, 5002, 5003 ...

Credentials

I like to have the credentials as user id and password and the all imortant key in the template. I use several templates, one per user and one per use case. Scripting is so much fun!
The key is uploaded to .ssh/my_key and <user-name>_key.

If you do not supply credentials you need to ADD them to the cloud-init tab!

Download the script to your server:

wget https://raw.githubusercontent.com/nallej/MyJourney/main/scripts/myTemplateBuilder.sh

Howe to use this script

  1. Edit the script - remember it's for general use
    1. Edit the key name
    2. Add any part you need
  2. Run the script
  3. Edit the VM Hardware tab according to your use case
  4. Edit the VM Cloud-init tab according to your use case
  5. Edit the VM Options tab according to your use case
  6. For K8s options see this post

Deltest.sh

This script is for deleting what was made by the previous script

Download the script to your server:

wget https://raw.githubusercontent.com/nallej/MyJourney/main/deltest.sh

Remove a node or a whole cluster

Some times we need to scrap a server, they get to old at times.
Some times we need to reconfigure a cluster and need to separate all nodes.

NOTE to be able to join a cluster the nodes can't have any CT/VM's

StopDelCorosync.sh

If you need to separate a node just run it on one node an reboot. To delete the cluster totally run it on all servers and reboot the all.

  • The script will stop the corosync
  • Start the node as local
  • Delete corosync configurations
  • Restart the file-system

Some times there is remnants from the past on servers. You might still see the nodes (as inactive) on your standalone server. In that case you need to delete the remaining configurations from these directories:

  • /etc/pve/qemu-server
  • /etc/pve/lxc
  • /etc/pve/nodes/<OLD NODE>/qemu-server
  • /etc/pve/nodes/<OLD NODE>/lxc

Download the script to your server:

wget https://raw.githubusercontent.com/nallej/MyJourney/main/StopDelCorosync.sh

Make all scripts executable

chmod +x deltest.sh myTemplateBuilder.sh StopDelCorosync.sh