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
βοΈ 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"
}
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"
}
}
π Usage Steps
1. Initialize Terraform
terraform init
2. Plan
terraform plan -var-file=environments/dev.tfvars
3. Apply
terraform apply -var-file=environments/dev.tfvars
4. Destroy (optional)
terraform destroy -var-file=environments/dev.tfvars
π Outputs
cluster_name = "cluster-kubeadm"
vm_ipv4_address_vms = [
"192.168.100.220/24",
"192.168.100.223/24",
"192.168.100.224/24"
]
π 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!
Top comments (0)