Plan for spinning up 7 node kubernetes cluster; kazan!

- Defines controller & worker resources
- terraform.tfvars defines distinct nodes as a dictonary
- Output provides final vmid, name & template used
This commit is contained in:
2023-01-02 23:50:14 +01:00
parent 3f0549a792
commit 20f90c129f
4 changed files with 254 additions and 0 deletions

120
main.tf Normal file
View File

@@ -0,0 +1,120 @@
terraform {
required_providers {
proxmox = {
source = "telmate/proxmox"
version = ">= 2.9.10"
}
google = {
source = "hashicorp/google"
version = "4.27.0"
}
}
backend "gcs" {
bucket = "schleppe-tfstate"
prefix = "kazan"
}
# backend "local" {}
}
resource "proxmox_vm_qemu" "k8s-kazan-controllers" {
for_each = var.k8s_controllers
name = each.value.name
target_node = each.value.target_node
vmid = each.value.vmid
desc = "Kazan kubernetes cluster controller node: ${each.value.name}"
sockets = 1
cores = each.value.vcpu
memory = each.value.memory
cpu = "host"
clone = "kazan-master-template"
full_clone = true
agent = 1
onboot = true
boot = "cdn"
bootdisk = "scsi0"
os_type = "cloud-init"
hotplug = "network,disk,usb"
ipconfig0 = "ip=${each.value.ip}${each.value.subnet},gw=${each.value.gw}"
nameserver = local.nameserver
searchdomain = local.searchdomain
sshkeys = <<-EOF
%{for key in local.public_ssh_keys~}
${key}
%{endfor~}
EOF
disk {
type = "scsi"
storage = "local-lvm"
size = each.value.disk_size
backup = 0
}
network {
model = "virtio"
bridge = "vmbr0"
firewall = false
link_down = false
}
vga {
memory = 0
type = "serial0"
}
}
resource "proxmox_vm_qemu" "k8s-kazan-workers" {
for_each = var.k8s_workers
name = each.value.name
target_node = each.value.target_node
vmid = each.value.vmid
desc = "Kazan kubernetes cluster worker node: ${each.value.name}"
sockets = 1
cores = each.value.vcpu
memory = each.value.memory
cpu = "host"
clone = "kazan-master-template"
full_clone = true
agent = 1
onboot = true
boot = "cdn"
bootdisk = "scsi0"
os_type = "cloud-init"
hotplug = "network,disk,usb"
ipconfig0 = "ip=${each.value.ip}${each.value.subnet},gw=${each.value.gw}"
nameserver = local.nameserver
searchdomain = local.searchdomain
sshkeys = <<-EOF
%{for key in local.public_ssh_keys~}
${key}
%{endfor~}
EOF
disk {
type = "scsi"
storage = "local-lvm"
size = each.value.disk_size
backup = 0
}
network {
model = "virtio"
bridge = "vmbr0"
firewall = false
link_down = false
}
vga {
type = "serial0"
}
}

43
outputs.tf Normal file
View File

@@ -0,0 +1,43 @@
# Controller outputs
output "controller_vm_id" {
description = "The VM Id"
value = {
for k, vm in proxmox_vm_qemu.k8s-kazan-controllers : k => vm.id
}
}
output "controller_vm_name" {
description = "The VM name"
value = {
for k, vm in proxmox_vm_qemu.k8s-kazan-controllers : k => vm.name
}
}
output "controller_clone" {
description = "Template name that this VM was cloned from"
value = {
for k, vm in proxmox_vm_qemu.k8s-kazan-controllers : k => vm.clone
}
}
# Worker outputs
output "worker_vm_id" {
description = "The VM Id"
value = {
for k, vm in proxmox_vm_qemu.k8s-kazan-workers : k => vm.id
}
}
output "worker_vm_name" {
description = "The VM name"
value = {
for k, vm in proxmox_vm_qemu.k8s-kazan-workers : k => vm.name
}
}
output "worker_clone" {
description = "Template name that this VM was cloned from"
value = {
for k, vm in proxmox_vm_qemu.k8s-kazan-workers : k => vm.clone
}
}

82
terraform.tfvars Normal file
View File

@@ -0,0 +1,82 @@
k8s_controllers = {
lb1 = {
target_node = "apollo",
vcpu = "2",
memory = "2048",
disk_size = "10G",
name = "lb1.kazan.schleppe",
vmid = 440
ip = "10.0.0.140",
subnet = "/24",
gw = "10.0.0.1"
},
c1 = {
target_node = "apollo",
vcpu = "2",
memory = "2048",
disk_size = "10G",
name = "c1.kazan.schleppe",
vmid = 441
ip = "10.0.0.141",
subnet = "/24",
gw = "10.0.0.1"
},
c2 = {
target_node = "apollo",
vcpu = "2",
memory = "2048",
disk_size = "10G",
name = "c2.kazan.schleppe",
vmid = 442
ip = "10.0.0.142",
subnet = "/24",
gw = "10.0.0.1"
},
c3 = {
target_node = "apollo",
vcpu = "2",
memory = "2048",
disk_size = "10G",
name = "c3.kazan.schleppe",
vmid = 443
ip = "10.0.0.143",
subnet = "/24",
gw = "10.0.0.1"
}
}
k8s_workers = {
w1 = {
target_node = "apollo",
vcpu = "2",
memory = "2048",
disk_size = "10G",
name = "w1.kazan.schleppe",
vmid = 444
ip = "10.0.0.144",
subnet = "/24",
gw = "10.0.0.1"
},
w2 = {
target_node = "apollo",
vcpu = "2",
memory = "2048",
disk_size = "10G",
name = "w2.kazan.schleppe",
vmid = 445
ip = "10.0.0.145",
subnet = "/24",
gw = "10.0.0.1"
},
w3 = {
target_node = "apollo",
vcpu = "2",
memory = "2048",
disk_size = "10G",
name = "w3.kazan.schleppe",
vmid = 446
ip = "10.0.0.146",
subnet = "/24",
gw = "10.0.0.1"
}
}

9
variables.tf Normal file
View File

@@ -0,0 +1,9 @@
variable "k8s_controllers" {
description = "k8s controller node variables as a dictionary"
type = map(any)
}
variable "k8s_workers" {
description = "k8s worker node variables as a dictionary"
type = map(any)
}