Configurazione iniziale per cluster k8s su Proxmox
This commit is contained in:
144
main.tf
Normal file
144
main.tf
Normal file
@@ -0,0 +1,144 @@
|
||||
# main.tf
|
||||
|
||||
terraform {
|
||||
required_providers {
|
||||
proxmox = {
|
||||
source = "telmate/proxmox"
|
||||
version = "3.0.1-rc2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "proxmox" {
|
||||
pm_api_url = "https://192.168.178.11:8006/api2/json"
|
||||
pm_tls_insecure = true
|
||||
}
|
||||
|
||||
# --- Variabili Locali per una facile configurazione ---
|
||||
locals {
|
||||
proxmox_node = "Covenant"
|
||||
template_name = "debian-12-cloudinit"
|
||||
ssh_user = "debian"
|
||||
k8s_version = "1.29.3-1.1"
|
||||
gateway_ip = "10.66.99.254"
|
||||
dns_server = "10.66.99.254"
|
||||
ssh_public_key = file("~/.ssh/id_ecdsa.pub")
|
||||
ssh_private_key = file("~/.ssh/id_ecdsa")
|
||||
|
||||
control_planes = {
|
||||
Alessandro = { ip = "10.66.99.171", vmid = 451 }
|
||||
Rene = { ip = "10.66.99.172", vmid = 452 }
|
||||
Arianna = { ip = "10.66.99.173", vmid = 453 }
|
||||
}
|
||||
|
||||
workers = {
|
||||
Stanis = { ip = "10.66.99.175", vmid = 455 }
|
||||
Itala = { ip = "10.66.99.176", vmid = 456 }
|
||||
Duccio = { ip = "10.66.99.177", vmid = 457 }
|
||||
}
|
||||
}
|
||||
|
||||
# --- Nodi Control Plane ---
|
||||
resource "proxmox_vm_qemu" "k8s_control_planes" {
|
||||
for_each = local.control_planes
|
||||
|
||||
vmid = each.value.vmid
|
||||
name = each.key
|
||||
target_node = local.proxmox_node
|
||||
clone = local.template_name
|
||||
os_type = "cloud-init"
|
||||
agent = 1
|
||||
|
||||
cores = 2
|
||||
sockets = 1
|
||||
memory = 4096
|
||||
|
||||
# Blocco "disks" corretto (plurale)
|
||||
disks {
|
||||
scsi {
|
||||
scsi0 {
|
||||
disk {
|
||||
storage = "MD-3"
|
||||
size = 40
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
network {
|
||||
model = "virtio"
|
||||
bridge = "vmbr0"
|
||||
}
|
||||
|
||||
# Argomenti "flat" per la configurazione iniziale
|
||||
ipconfig0 = "ip=${each.value.ip}/24,gw=${local.gateway_ip}"
|
||||
nameserver = local.dns_server
|
||||
sshkeys = local.ssh_public_key
|
||||
|
||||
# Provisioner per eseguire lo script di setup
|
||||
provisioner "remote-exec" {
|
||||
connection {
|
||||
type = "ssh"
|
||||
user = local.ssh_user
|
||||
private_key = local.ssh_private_key
|
||||
host = self.default_ipv4_address
|
||||
}
|
||||
inline = split("\n", templatefile("cloud-init-script.yaml", {
|
||||
k8s_version = local.k8s_version
|
||||
is_control_plane = true
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
# --- Nodi Worker ---
|
||||
resource "proxmox_vm_qemu" "k8s_workers" {
|
||||
for_each = local.workers
|
||||
|
||||
vmid = each.value.vmid
|
||||
name = each.key
|
||||
target_node = local.proxmox_node
|
||||
clone = local.template_name
|
||||
os_type = "cloud-init"
|
||||
agent = 1
|
||||
|
||||
cores = 2
|
||||
sockets = 1
|
||||
memory = 2048
|
||||
|
||||
# Blocco "disks" corretto (plurale)
|
||||
disks {
|
||||
scsi {
|
||||
scsi0 {
|
||||
disk {
|
||||
storage = "MD-3"
|
||||
size = 25
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
network {
|
||||
model = "virtio"
|
||||
bridge = "vmbr0"
|
||||
}
|
||||
|
||||
# Argomenti "flat" per la configurazione iniziale
|
||||
ipconfig0 = "ip=${each.value.ip}/24,gw=${local.gateway_ip}"
|
||||
nameserver = local.dns_server
|
||||
sshkeys = local.ssh_public_key
|
||||
|
||||
# Provisioner per eseguire lo script di setup
|
||||
provisioner "remote-exec" {
|
||||
connection {
|
||||
type = "ssh"
|
||||
user = local.ssh_user
|
||||
private_key = local.ssh_private_key
|
||||
host = self.default_ipv4_address
|
||||
}
|
||||
inline = split("\n", templatefile("cloud-init-script.yaml", {
|
||||
k8s_version = local.k8s_version
|
||||
is_control_plane = false
|
||||
}))
|
||||
}
|
||||
depends_on = [proxmox_vm_qemu.k8s_control_planes]
|
||||
}
|
||||
Reference in New Issue
Block a user