/terraform_proxmox_vm

Provision Proxmox VM's using Terraform

Primary LanguageShell

Proxmox : Terraform : K3S

Assumptions

  • You have a Proxmox Server/Cluster capable of running 4+ Linux VM's
  • You have an Internet Connection
  • You're comfortable with the CLI in Linux
  • Understand containerization concepts
  • Watch lots of home lab YouTube content :)

Order of operations

  • Create Proxmox User w/ API Token
  • Create VM template via 'build_cloud_image_vm_template.sh' (must be done on proxmox host)
    • edit script to fit your proxmox environment
      • VMID
      • TMPL_NAME
      • TMPL_DESCRIPTION
      • PVE_DISK
      • DISK_SZ
      • PVE_NODE
    • assign ssh public key in build script for cloud init drive
    • Currently designed to create Ubuntu 23.04 Cloud Image VM/Template
ssh root@pve-6
apt update -y && apt install libguestfs-tools -y
cd k3s_deployment/modules/pm_vm_template
  • Add SSH public keys to the id_sshkeys.pub file as this file is used to seed the cloud image drive.
  • Change variables in build_cloud_image_vm_template.sh to ensure you're pointing to the right PVE SERVER, PVE DISK, etc.

E48EEBCB-EC90-4F72-BDEC-BBF7299F596E

bash ./build_vm_template.sh

image

VIRTUAL MACHINE TEMPLATE: [9900 - ubun2204-k3s-tmpl-01] image

  • Provision 5 - 6 VM's from VM template using Terraform
    • 3 Server Nodes and 2 - 3 Worker Nodes
      • Server Nodes: 2 CPU / 4 GB RAM (2 GB min)
      • Worker Nodes: 2 CPU / 8 GB RAM
    • edit terraform.tfvars and main.tf as required
    • assign static ip scheme to support K3S deployment

terraform init
terraform apply -auto-approve

image


K3S SRVR::VIRTUAL MACHINES: [7701/2/3 - k3s-srvr-nodes-(1-3)] FROM THE TEMPLATE ON PVE-6: [9900 - ubun2204-k3s-tmpl-01] image

K3S WRKR::VIRTUAL MACHINES: [7201/2/3 - k3s-wrkr-nodes-(1-3)] FROM THE TEMPLATE ON PVE-5: [9200 - ubun2204-k3s-tmpl-02] image


image

  • Execute K3S deployment script
./k3s.sh

ENJOY and begin to containerize all the things!
Major Shout Out to all of the YouTube Home Lab content creators that helped me create this solution!

image

Set up Rancher (Branch: Alpha)

helm repo add rancher-alpha https://releases.rancher.com/server-charts/alpha
kubectl create namespace cattle-system
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.11.0/cert-manager.crds.yaml
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm install cert-manager jetstack/cert-manager \
  --namespace cert-manager \
  --create-namespace --version v1.11.0
kubectl get pods --namespace cert-manager
helm install rancher rancher-alpha/rancher --devel \
  --namespace cattle-system \
  --set hostname=rancher.cloudhunters.io \
  --set bootstrapPassword=admin
kubectl -n cattle-system rollout status deploy/rancher
kubectl -n cattle-system get deploy rancher
kubectl expose deployment rancher --name rancher-lb --port=443 --type=LoadBalancer -n cattle-system service/rancher-lb exposed
  • Rancher - K3S GUI Management Console

349B9361-75BD-4F5F-B473-5943E35DD2F5

08E62692-E6E4-4CB0-A289-19C5BA697C92

449034E0-3672-4194-A3B1-6B047A892347