DEV Community

RAUL TAPARA YANGALI
RAUL TAPARA YANGALI

Posted on

πŸš€ StackOpsys: Part 2-Automating Kubernetes Infrastructure on Proxmox with Packer, Terraform and Ansible

In the first part of StackOpsys, we built a secure, cloud-init-ready image for Kubernetes using Packer. Now it’s time for Part 2: automating the creation of Kubernetes cluster infrastructure using Terraform on Proxmox VE.


🧱 What’s included in this phase?

βœ… Creation of VMs (master + workers) based on the custom Ubuntu 22.04 template

βœ… Modular structure with a reusable vms_proxmox Terraform module

βœ… Network bridge configuration, fixed IPs, and cloud-init enabled

βœ… Support for multiple environments (dev, QA, prod) using .tfvars


πŸ“¦ Technologies

  • 🧰 Terraform 1.8+
  • ☁️ Proxmox VE 8.3.3+
  • 🐧 Ubuntu Server 22.04 LTS

πŸ“ Project Structure Overview

terraform/
β”œβ”€β”€ environments/
β”‚   β”œβ”€β”€ dev.tfvars
β”‚   └── prd.tfvars
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ vms_proxmox/
β”‚   └── tools_k8s/
β”œβ”€β”€ main.tf
β”œβ”€β”€ variables.tf
β”œβ”€β”€ outputs.tf
β”œβ”€β”€ providers.tf
└── .github/workflows/terraform.yaml
Enter fullscreen mode Exit fullscreen mode

βš™οΈ Configuration Examples

Proxmox Access

proxmox = {
  endpoint  = "https://192.168.100.100:8006/api2/json"
  username  = "root"
  password  = "your_password"
  api_token = "root@pam!iac-tf=your_token"
}
Enter fullscreen mode Exit fullscreen mode

Cluster & VMs

cluster = {
  name     = "cluster-kubeadm"
  gateway  = "192.168.100.1"
  cidr     = 24
  endpoint = "192.168.100.220"
}

vms = {
  "k8s-master-01" = {
    ip            = "192.168.100.220"
    cpu           = 4
    ram_dedicated = 4096
    file_id       = "directory:9001/base-9001-disk-0.qcow2"
  }
}
Enter fullscreen mode Exit fullscreen mode

πŸš€ Usage Steps

1. Initialize Terraform

terraform init
Enter fullscreen mode Exit fullscreen mode

2. Plan

terraform plan -var-file=environments/dev.tfvars
Enter fullscreen mode Exit fullscreen mode

plan

3. Apply

terraform apply -var-file=environments/dev.tfvars
Enter fullscreen mode Exit fullscreen mode

apply

4. Destroy (optional)

terraform destroy -var-file=environments/dev.tfvars
Enter fullscreen mode Exit fullscreen mode

πŸ” Outputs

cluster_name = "cluster-kubeadm"
vm_ipv4_address_vms = [
  "192.168.100.220/24",
  "192.168.100.223/24",
  "192.168.100.224/24"
]
Enter fullscreen mode Exit fullscreen mode

πŸ”„ GitHub Actions Pipeline

Includes:

  • Terraform init/plan/validate/apply
  • Secrets stored securely in GitHub
  • Reproducible infrastructure builds

βœ… What’s next?

In Part 3, we’ll use Ansible to:

  • Install required packages on each VM
  • Configure kubeadm on the master node
  • Join the worker nodes automatically
  • Deploy networking (e.g., Calico) and additional tools

πŸ“– Full code and documentation on GitHub

Follow along and let me know what you'd add!

DevOps #Terraform #Kubernetes #IaC #Proxmox #Ansible #CI/CD #CloudInit #StackOpsys

Top comments (0)