homelab/proxmox/adder/clone-vm.sh
Samantha Atkins 759ef949bc K3s cluster on Proxmox with WireGuard mesh networking
Replaced Headscale (too buggy in 0.28.x — random node drops) with direct
WireGuard hub-and-spoke + full mesh. 7 Proxmox VMs across 3 hosts form a
K3s v1.34.6 cluster: 3 control-plane/etcd nodes, 4 workers.

Running services: postgres, mariadb, ghost (x3), forgejo, authentik.
All unpinned services use local-path StorageClass. Databases pinned to
pve-worker and adder-worker with local PVs.

Includes VM provisioning scripts (create-debian-template.sh, clone-vm.sh),
K3s manifests for all services, and full deployment docs in k3s/README.md.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 01:23:13 -04:00

47 lines
1.5 KiB
Bash

#!/bin/bash
# clone-vm.sh
# Clones a Proxmox VM template into a new full VM.
# Run this on the same node where the template lives (local storage).
#
# Usage:
# ./clone-vm.sh <TEMPLATE_VMID> <NEW_VMID> <NAME> [CORES] [MEMORY_MB] [DISK_SIZE]
#
# Examples:
# ./clone-vm.sh 100 101 k3s-control-1
# ./clone-vm.sh 100 202 k3s-worker-1 6 8192 100G
#
# Defaults:
# CORES = 2
# MEMORY_MB = 2048
# DISK_SIZE = 20G
#
# Note: Template must exist on the local node (local-lvm).
# Run create-debian-template.sh on each node first.
set -euo pipefail
TEMPLATE_VMID="${1:?Usage: $0 <TEMPLATE_VMID> <NEW_VMID> <NAME> [CORES] [MEMORY_MB] [DISK_SIZE]}"
NEW_VMID="${2:?Usage: $0 <TEMPLATE_VMID> <NEW_VMID> <NAME> [CORES] [MEMORY_MB] [DISK_SIZE]}"
NAME="${3:?Usage: $0 <TEMPLATE_VMID> <NEW_VMID> <NAME> [CORES] [MEMORY_MB] [DISK_SIZE]}"
CORES="${4:-2}"
MEMORY="${5:-2048}"
DISK_SIZE="${6:-20G}"
echo "==> Cloning template ${TEMPLATE_VMID} to ${NEW_VMID} (${NAME})..."
qm clone "${TEMPLATE_VMID}" "${NEW_VMID}" --name "${NAME}" --full
echo "==> Setting resources: ${CORES} cores, ${MEMORY}MB RAM..."
qm set "${NEW_VMID}" --cores "${CORES}" --memory "${MEMORY}"
echo "==> Resizing disk to ${DISK_SIZE}..."
qm resize "${NEW_VMID}" scsi0 "${DISK_SIZE}"
echo "==> Setting hostname via Cloud-Init..."
qm set "${NEW_VMID}" --ciuser samantha --ipconfig0 ip=dhcp
echo "==> Starting VM..."
qm start "${NEW_VMID}"
echo ""
echo "Done. VM ${NEW_VMID} (${NAME}) started."
echo "Find its IP: qm guest cmd ${NEW_VMID} network-get-interfaces"