# Talos Cluster on Proxmox - Terraform Configuration This Terraform project creates and provisions a Talos Kubernetes cluster on Proxmox VE with integrated Proxmox Cloud Controller Manager (CCM) and Container Storage Interface (CSI) driver. ## Features - 🚀 **Automated VM provisioning** on Proxmox VE - ☁️ **Proxmox Cloud Controller Manager** - Native Proxmox integration for Kubernetes - 💾 **Proxmox CSI Driver** - Dynamic volume provisioning using Proxmox storage - 🔄 **High Availability** - Multi-node control plane with optional VIP - 🌐 **Flexible networking** - DHCP or static IP configuration - 📦 **Full stack deployment** - From VMs to running Kubernetes cluster ## Prerequisites 1. **Proxmox VE** server with API access 2. **Terraform** >= 1.0 3. **SSH access** to Proxmox node 4. **Network requirements**: - Available IP addresses for VMs (DHCP or static) - Network connectivity between VMs - Access to download Talos ISO (for initial setup) ## Quick Start ### 1. Create terraform.tfvars Create a `terraform.tfvars` file with your Proxmox and cluster configuration: ```hcl # Proxmox Connection proxmox_endpoint = "https://proxmox.example.com:8006" proxmox_username = "root@pam" proxmox_password = "your-password" proxmox_node = "pve" # Proxmox API Tokens (required for CCM/CSI) proxmox_ccm_token_secret = "your-ccm-token-secret" proxmox_csi_token_secret = "your-csi-token-secret" # Cluster Configuration cluster_name = "talos-cluster" cluster_endpoint = "https://10.0.0.100:6443" # VM Configuration controlplane_count = 3 worker_count = 2 # Network (DHCP - IPs will be auto-assigned) # For static IPs, see advanced configuration below ``` ### 2. Initialize and Apply ```bash terraform init terraform plan terraform apply ``` ### 3. Get Cluster Access ```bash # Get talosconfig terraform output -raw talosconfig > ~/.talos/config # Get kubeconfig terraform output -raw kubeconfig > ~/.kube/config # Verify cluster talosctl version --nodes kubectl get nodes ``` ### 4. Verify Proxmox Integration ```bash # Check CCM is running kubectl get pods -n kube-system | grep proxmox-cloud-controller # Check CSI is running kubectl get pods -n csi-proxmox # View available storage classes kubectl get storageclass # Create a test PVC kubectl apply -f - < topology.kubernetes.io/zone: ``` ### Container Storage Interface (CSI) The CSI driver provides: - **Dynamic Provisioning**: Automatically create volumes in Proxmox storage - **Volume Expansion**: Support for expanding PVCs - **Multiple Storage Backends**: Use any Proxmox storage (LVM, ZFS, Ceph, NFS, etc.) Example usage: ```yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: my-data spec: accessModes: - ReadWriteOnce resources: requests: storage: 50Gi storageClassName: proxmox-data ``` ## Accessing the Cluster ### Talos CLI ```bash # Export talosconfig terraform output -raw talosconfig > ~/.talos/config # Get nodes talosctl get members # Get service status talosctl services # Access logs talosctl logs kubelet ``` ### Kubernetes CLI ```bash # Export kubeconfig terraform output -raw kubeconfig > ~/.kube/config # Get cluster info kubectl cluster-info kubectl get nodes -o wide kubectl get pods -A # Check Proxmox integrations kubectl get pods -n kube-system | grep proxmox kubectl get pods -n csi-proxmox kubectl get storageclass ``` ## Maintenance ### Upgrading Talos ```bash # Update talos_version variable talos_version = "v1.9.2" # Apply changes terraform apply # Or upgrade manually talosctl upgrade --image ghcr.io/siderolabs/installer:v1.9.2 ``` ### Scaling Workers ```bash # Update worker_count worker_count = 5 # Apply changes terraform apply ``` ### Removing the Cluster ```bash terraform destroy ``` ## Troubleshooting ### VMs not getting IP addresses **For DHCP:** - Check Proxmox network bridge configuration - Verify DHCP server is running on the network - Ensure VMs are connected to the correct network bridge **For Static IPs:** - Verify all required parameters are set: `controlplane_ips`/`worker_ips`, `gateway`, and `netmask` - Check that IPs are in the correct subnet - Ensure gateway IP is correct and reachable - Verify no IP conflicts with existing devices ### Cannot connect to nodes - Verify firewall rules allow port 50000 (Talos API) - Check VM networking in Proxmox - Ensure nodes are in maintenance mode: `talosctl version --nodes ` ### Bootstrap fails - Check control plane IPs are correct - Verify cluster_endpoint is accessible - Review logs: `talosctl logs etcd` ### ISO upload fails - Verify SSH access to Proxmox node - Check `/var/lib/vz/template/iso/` permissions - Manually upload ISO if needed ### CCM/CSI not working - Verify Proxmox API token secrets are correct - Check that tokens have appropriate permissions in Proxmox - Review template logs for CCM/CSI configuration ## Project Structure ``` . ├── main.tf # Main VM and Talos resources ├── variables.tf # Input variables ├── outputs.tf # Output values (talosconfig, kubeconfig) ├── versions.tf # Provider versions (Talos, Proxmox) ├── locals.tf # Local values and computed variables ├── state.tf # Remote state configuration ├── terraform.tfvars # Your configuration (not in git) ├── terraform.tfvars.example # Example configuration template ├── templates/ │ ├── install-disk-and-hostname.yaml.tmpl # Hostname and disk config │ ├── static-ip.yaml.tmpl # Static IP configuration │ ├── vip-config.yaml.tmpl # VIP configuration for HA │ └── proxmox-ccm.yaml.tmpl # Proxmox CCM/CSI configuration └── files/ ├── cp-scheduling.yaml # Control plane scheduling config └── cloud-provider.yaml # Cloud provider config ``` ## References - [Talos Documentation](https://www.talos.dev/) - [Talos Terraform Provider](https://registry.terraform.io/providers/siderolabs/talos) - [Proxmox Terraform Provider](https://registry.terraform.io/providers/bpg/proxmox) - [Proxmox CCM](https://github.com/sergelogvinov/proxmox-cloud-controller-manager) - [Proxmox CSI](https://github.com/sergelogvinov/proxmox-csi-plugin) - [Siderolabs Contrib Examples](https://github.com/siderolabs/contrib/tree/main/examples/terraform) ## License Based on examples from [siderolabs/contrib](https://github.com/siderolabs/contrib)