-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_k8s_nodes.tf
More file actions
195 lines (175 loc) · 5.18 KB
/
Copy pathtest_k8s_nodes.tf
File metadata and controls
195 lines (175 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
locals {
worker_name = "kworker"
master_name = "kmaster"
k8s_start_id = 301
worker_cpu = 4
worker_ram = 2048
worker_disk = 30
worker_count = 2
master_cpu = 2
master_ram = 4096
master_disk = 30
master_count = 1
k8s_initial_cidr = "10.0.1.0/24"
k8s_subnet_offset = 11
}
resource "proxmox_virtual_environment_vm" "master" {
count = local.master_count
name = "${local.master_name}${count.index + 1}"
node_name = var.target_node
vm_id = local.k8s_start_id + count.index
cpu {
architecture = "x86_64"
type = "x86-64-v2-AES"
cores = local.master_cpu
sockets = 1
}
agent {
enabled = true
}
memory {
dedicated = local.master_ram
}
network_device {
bridge = "k8s"
# vlan_id = var.k8s_vlan_id
}
operating_system {
type = "l26"
}
initialization {
ip_config {
ipv4 {
address = "${cidrhost(local.k8s_initial_cidr, local.k8s_subnet_offset + count.index)}/24"
gateway = var.k8s_gw
}
}
user_data_file_id = proxmox_virtual_environment_file.master[count.index].id
}
disk {
size = local.master_disk
file_id = "local:iso/Rocky-9-GenericCloud-LVM-9.4-20240609.0.x86_64.qcow2.iso"
datastore_id = "local-lvm"
interface = "scsi0"
}
boot_order = ["scsi0"]
}
resource "proxmox_virtual_environment_file" "master" {
count = local.master_count
content_type = "snippets"
datastore_id = "local"
node_name = var.target_node
source_raw {
data = <<-EOF
#cloud-config
hostname: ${local.master_name}${count.index + 1}
fqdn: ${local.master_name}${count.index + 1}.home
users:
- name: ${var.vm_username}
ssh_authorized_keys:
- ${file(var.ssh_public_key)}
groups:
- sudo
- docker
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
package_update: true
package_upgrade: true
runcmd:
- setenforce 0
- sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
- dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
- yum install -y epel-release
- yum install -y tmux vim htop iftop iotop fastfetch docker-ce
- systemctl enable --now docker
- echo "done" > /tmp/cloud-config.done
timezone: Europe/Moscow
EOF
file_name = "cloud-config-${local.master_name}${count.index + 1}-${local.k8s_start_id + count.index}.yaml"
}
}
resource "mikrotik_dns_record" "k8s_master" {
count = local.master_count
name = "${local.master_name}${count.index + 1}.home"
address = cidrhost(local.k8s_initial_cidr, local.k8s_subnet_offset + count.index)
}
resource "proxmox_virtual_environment_vm" "worker" {
count = local.worker_count
name = "${local.worker_name}${count.index + 1}"
node_name = var.target_node
vm_id = local.k8s_start_id + local.master_count + count.index
cpu {
architecture = "x86_64"
type = "x86-64-v2-AES"
cores = local.worker_cpu
sockets = 1
}
agent {
enabled = true
}
memory {
dedicated = local.worker_ram
}
network_device {
bridge = "k8s"
# vlan_id = var.k8s_vlan_id
}
operating_system {
type = "l26"
}
initialization {
ip_config {
ipv4 {
address = "${cidrhost(local.k8s_initial_cidr, local.k8s_subnet_offset + local.master_count + count.index)}/24"
gateway = var.k8s_gw
}
}
user_data_file_id = proxmox_virtual_environment_file.worker[count.index].id
}
disk {
size = local.worker_disk
file_id = "local:iso/Rocky-9-GenericCloud-LVM-9.4-20240609.0.x86_64.qcow2.iso"
datastore_id = "local-lvm"
interface = "scsi0"
}
boot_order = ["scsi0"]
}
resource "proxmox_virtual_environment_file" "worker" {
count = local.worker_count
content_type = "snippets"
datastore_id = "local"
node_name = var.target_node
source_raw {
data = <<-EOF
#cloud-config
hostname: ${local.worker_name}${count.index + 1}
fqdn: ${local.worker_name}${count.index + 1}.home
users:
- name: ${var.vm_username}
ssh_authorized_keys:
- ${file(var.ssh_public_key)}
groups:
- sudo
- docker
shell: /bin/bash
sudo: ALL=(ALL) NOPASSWD:ALL
package_update: true
package_upgrade: true
runcmd:
- setenforce 0
- sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
- dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
- yum install -y epel-release
- yum install -y tmux vim htop iftop iotop fastfetch docker-ce
- systemctl enable --now docker
- echo "done" > /tmp/cloud-config.done
timezone: Europe/Moscow
EOF
file_name = "cloud-config-${local.worker_name}${count.index + 1}-${local.k8s_start_id + count.index}.yaml"
}
}
resource "mikrotik_dns_record" "k8s_worker" {
count = local.worker_count
name = "${local.worker_name}${count.index + 1}.home"
address = cidrhost(local.k8s_initial_cidr, local.k8s_subnet_offset + local.master_count + count.index)
}