Compare commits

...

2 Commits

Author SHA1 Message Date
Iurii Anfinogenov
326572de4d add rocky image 2026-05-04 06:30:51 +00:00
Iurii Anfinogenov
40694927c8 commit fix 2026-05-03 13:23:54 +00:00
10 changed files with 406 additions and 40 deletions

View File

@@ -0,0 +1,21 @@
#cloud-config
timezone: Europe/Moscow
users:
- name: iurii
groups: [wheel]
shell: /bin/bash
lock_passwd: false
passwd: "$6$Zc8nwvtw0Kns5.sD$FpQ4aBSeGogefqjM4we4U5QQd4YBtC98tuG3rR4j9ZmbtC1kyFf2sY/IodYW3wG.U81aEntlZrtOTOqw3ZcOc0"
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
ssh_authorized_keys:
- ${ssh_key}
package_update: true
packages:
- qemu-guest-agent
runcmd:
- systemctl enable --now qemu-guest-agent
- hostnamectl set-hostname ${hostname}

View File

@@ -99,7 +99,8 @@
locals { locals {
nodes = { nodes = {
k8s-master-1 = { k8s-master-1 = {
cloudinit = "master.yml" cloudinit = "rocky.yml"
image_file = "import/rocky9.qcow2"
index = 1 index = 1
cpu = var.worker_cpu cpu = var.worker_cpu
memory = 4092 memory = 4092
@@ -115,45 +116,45 @@ locals {
gateway = "192.168.20.1" gateway = "192.168.20.1"
} }
] ]
},
k8s-worker-1 = {
cloudinit = "worker.yml"
index = 2
cpu = var.worker_cpu
memory = 8192
disk = var.worker_disk
datastore = var.worker_datastore
network_devices = [
{
bridge = var.node_bridge
vlan_id = 20
ip = "192.168.20.22"
cidr = 24
gateway = "192.168.20.1"
}
]
},
k8s-worker-2 = {
cloudinit = "worker.yml"
index = 3
cpu = var.worker_cpu
memory = 8192
disk = var.worker_disk
datastore = var.worker_datastore
network_devices = [
{
bridge = var.node_bridge
vlan_id = 20
ip = "192.168.20.23"
cidr = 24
gateway = "192.168.20.1"
},
{
bridge = "vmbr0"
}
]
} }
# k8s-worker-1 = {
# cloudinit = "worker.yml"
# index = 2
# cpu = var.worker_cpu
# memory = 8192
# disk = var.worker_disk
# datastore = var.worker_datastore
# network_devices = [
# {
# bridge = var.node_bridge
# vlan_id = 20
# ip = "192.168.20.22"
# cidr = 24
# gateway = "192.168.20.1"
# }
# ]
# },
# k8s-worker-2 = {
# cloudinit = "worker.yml"
# index = 3
# cpu = var.worker_cpu
# memory = 8192
# disk = var.worker_disk
# datastore = var.worker_datastore
# network_devices = [
# {
# bridge = var.node_bridge
# vlan_id = 20
# ip = "192.168.20.23"
# cidr = 24
# gateway = "192.168.20.1"
# },
# {
# bridge = "vmbr0"
# }
# ]
# }
} }
} }

124
example_locals.tf Normal file
View File

@@ -0,0 +1,124 @@
locals {
nodes = {
k8s-worker-1 = {
index = 1
cpu = 2
memory = 2048
disks = [
{
datastore = "ssd2"
interface = "scsi0"
size = 20
import_from = "local:import/ubuntu-24.qcow2"
}
]
network_devices = [
{
bridge = "vmbr0"
vlan_id = 20
ip = "192.168.20.10"
cidr = 24
gateway = "192.168.20.1"
}
]
},
k8s-worker-2 = {
index = 2
cpu = 2
memory = 2048
disks = [
{
datastore = "ssd2"
interface = "scsi0"
size = 20
import_from = "local:import/ubuntu-24.qcow2"
}
]
network_devices = [
{
bridge = "vmbr0"
vlan_id = 20
ip = "192.168.20.11"
cidr = 24
gateway = "192.168.20.1"
}
]
},
k8s-worker-3 = {
index = 3
cpu = 2
memory = 2048
disks = [
{
datastore = "ssd2"
interface = "scsi0"
size = 20
import_from = "local:import/ubuntu-24.qcow2"
}
]
network_devices = [
{
bridge = "vmbr0"
vlan_id = 20
ip = "192.168.20.12"
cidr = 24
gateway = "192.168.20.1"
}
]
},
k8s-worker-4 = {
index = 4
cpu = 2
memory = 2048
disks = [
{
datastore = "ssd2"
interface = "scsi0"
size = 20
import_from = "local:import/ubuntu-24.qcow2"
}
]
network_devices = [
{
bridge = "vmbr0"
vlan_id = 20
ip = "192.168.20.13"
cidr = 24
gateway = "192.168.20.1"
}
]
},
k8s-worker-5 = {
index = 5
cpu = 2
memory = 2048
disks = [
{
datastore = "ssd2"
interface = "scsi0"
size = 20
import_from = "local:import/ubuntu-24.qcow2"
}
]
network_devices = [
{
bridge = "vmbr0"
vlan_id = 20
ip = "192.168.20.14"
cidr = 24
gateway = "192.168.20.1"
}
]
}
}
}

54
generate.py Normal file
View File

@@ -0,0 +1,54 @@
#!/usr/bin/env python3
BASE_IP = "192.168.20"
START = 10
COUNT = 5
CPU = 2
MEMORY = 2048
GATEWAY = "192.168.20.1"
def generate():
print("locals {")
print(" nodes = {")
for i in range(COUNT):
idx = i + 1
last_octet = START + i
if last_octet > 254:
raise ValueError("IP overflow")
ip = f"{BASE_IP}.{last_octet}"
comma = "," if i < COUNT - 1 else ""
print(f""" k8s-worker-{idx} = {{
index = {idx}
cpu = {CPU}
memory = {MEMORY}
disks = [
{{
datastore = "ssd2"
interface = "scsi0"
size = 20
import_from = "local:import/ubuntu-24.qcow2"
}}
]
network_devices = [
{{
bridge = "vmbr0"
vlan_id = 20
ip = "{ip}"
cidr = 24
gateway = "{GATEWAY}"
}}
]
}}{comma}""")
print(" }")
print("}")
if __name__ == "__main__":
generate()

View File

@@ -0,0 +1,34 @@
#cloud-config
# Создать passwd hash: openssl passwd -6
timezone: Europe/Moscow
users:
- name: iurii
groups: [sudo]
shell: /bin/bash
lock_passwd: false
passwd: "$6$Zc8nwvtw0Kns5.sD$FpQ4aBSeGogefqjM4we4U5QQd4YBtC98tuG3rR4j9ZmbtC1kyFf2sY/IodYW3wG.U81aEntlZrtOTOqw3ZcOc0"
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
ssh_authorized_keys:
- ${ssh_key}
package_update: true
packages:
- qemu-guest-agent
runcmd:
- systemctl enable --now qemu-guest-agent
- hostnamectl set-hostname ${hostname}
- systemctl disable --now packagekit
- systemctl disable --now ModemManager
- systemctl disable --now multipathd
write_files:
- path: /etc/motd
content: |
Managed by OpenTofu
final_message: "cloud-init finished"

View File

@@ -0,0 +1,34 @@
#cloud-config
# Создать passwd hash: openssl passwd -6
timezone: Europe/Moscow
users:
- name: iurii
groups: [sudo]
shell: /bin/bash
lock_passwd: false
passwd: "$6$Zc8nwvtw0Kns5.sD$FpQ4aBSeGogefqjM4we4U5QQd4YBtC98tuG3rR4j9ZmbtC1kyFf2sY/IodYW3wG.U81aEntlZrtOTOqw3ZcOc0"
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
ssh_authorized_keys:
- ${ssh_key}
package_update: true
packages:
- qemu-guest-agent
runcmd:
- systemctl enable --now qemu-guest-agent
- hostnamectl set-hostname ${hostname}
- systemctl disable --now packagekit
- systemctl disable --now ModemManager
- systemctl disable --now multipathd
write_files:
- path: /etc/motd
content: |
Managed by OpenTofu
final_message: "cloud-init finished"

34
lab/cloud-config/lab.yml Normal file
View File

@@ -0,0 +1,34 @@
#cloud-config
# Создать passwd hash: openssl passwd -6
timezone: Europe/Moscow
users:
- name: iurii
groups: [sudo]
shell: /bin/bash
lock_passwd: false
passwd: "$6$Zc8nwvtw0Kns5.sD$FpQ4aBSeGogefqjM4we4U5QQd4YBtC98tuG3rR4j9ZmbtC1kyFf2sY/IodYW3wG.U81aEntlZrtOTOqw3ZcOc0"
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
ssh_authorized_keys:
- ${ssh_key}
package_update: true
packages:
- qemu-guest-agent
runcmd:
- systemctl enable --now qemu-guest-agent
- hostnamectl set-hostname ${hostname}
- systemctl disable --now packagekit
- systemctl disable --now ModemManager
- systemctl disable --now multipathd
write_files:
- path: /etc/motd
content: |
Managed by OpenTofu
final_message: "cloud-init finished"

View File

@@ -32,6 +32,7 @@ resource "proxmox_virtual_environment_file" "cloudinit" {
resource "proxmox_virtual_environment_vm" "nodes" { resource "proxmox_virtual_environment_vm" "nodes" {
for_each = local.nodes for_each = local.nodes
tags = ["tofu"]
name = local.hostname_map[each.key] name = local.hostname_map[each.key]
node_name = var.proxmox_node node_name = var.proxmox_node
@@ -48,6 +49,8 @@ resource "proxmox_virtual_environment_vm" "nodes" {
cpu { cpu {
cores = each.value.cpu cores = each.value.cpu
type = "host"
} }
memory { memory {
@@ -63,12 +66,24 @@ resource "proxmox_virtual_environment_vm" "nodes" {
} }
} }
disk { dynamic "clone" {
for_each = try(each.value.template_id, null) == null ? [] : [each.value.template_id]
content {
vm_id = clone.value
}
}
dynamic "disk" {
for_each = try(each.value.template_id, null) == null ? [1] : []
content {
datastore_id = each.value.datastore datastore_id = each.value.datastore
import_from = "${var.image_datastore}:${var.image_file}" import_from = "${var.image_datastore}:${var.image_file}"
interface = var.disk_interface interface = var.disk_interface
size = each.value.disk size = each.value.disk
} }
}
dynamic "disk" { dynamic "disk" {
for_each = try([each.value.data_disk], []) for_each = try([each.value.data_disk], [])

View File

@@ -12,6 +12,7 @@ variable "nodes" {
vmid = optional(number) vmid = optional(number)
data_disk = optional(number) data_disk = optional(number)
cloudinit = optional(string) cloudinit = optional(string)
template_id = optional(number)
network_devices = list(object({ network_devices = list(object({
bridge = string bridge = string

48
setup_disk.sh Normal file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -euo pipefail
DISK="/dev/sdb"
PART="${DISK}1"
MOUNT_POINT="/u01"
echo "[1] Проверка диска"
lsblk "$DISK"
echo "[2] Создание GPT и раздела"
sudo parted "$DISK" --script mklabel gpt
sudo parted "$DISK" --script mkpart primary ext4 0% 100%
echo "[3] Ожидание появления раздела"
sleep 2
echo "[4] Форматирование"
sudo mkfs.ext4 -F "$PART"
echo "[5] Создание точки монтирования"
sudo mkdir -p "$MOUNT_POINT"
echo "[6] Получение UUID"
UUID=$(blkid -s UUID -o value "$PART")
if [[ -z "$UUID" ]]; then
echo "ERROR: UUID not found"
exit 1
fi
echo "[7] Добавление в fstab"
if ! grep -q "$UUID" /etc/fstab; then
echo "UUID=$UUID $MOUNT_POINT ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab
fi
echo "[8] Применение"
sudo systemctl daemon-reload
sudo mount -a
echo "[9] Проверка"
df -h | grep "$MOUNT_POINT"
echo "[10] Подготовка под OpenSearch"
sudo mkdir -p /u01/opensearch
sudo chown -R 1000:1000 /u01/opensearch
echo "DONE"