Skip to content

Commit 5097ba3

Browse files
zifeoKirubel-Fikru
andauthored
feat: kube-proxy mode (#62)
* feat:configure kube-proxy setup * feat:node label * feat:kube proxy resources * feat:add node labels * feat:add node labels * feat:add node labels * feat:node label variable * feat: node label per node * feat:node annotations --------- Co-authored-by: Kirubel-Fikru <[email protected]>
1 parent e52a013 commit 5097ba3

File tree

6 files changed

+130
-15
lines changed

6 files changed

+130
-15
lines changed

main.tf

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ module "servers" {
6262

6363
network_id = openstack_networking_network_v2.net.id
6464
subnet_id = openstack_networking_subnet_v2.servers.id
65+
cluster_cidr = var.cluster_cidr
66+
service_cidr = var.service_cidr
67+
cni = var.cni
6568
secgroup_id = openstack_networking_secgroup_v2.server.id
6669
internal_vip = local.internal_vip
6770
vip_interface = var.vip_interface
@@ -103,9 +106,10 @@ module "servers" {
103106
cluster_name = var.name
104107
}),
105108
"patches/rke2-cilium.yaml" : templatefile("${path.module}/patches/rke2-cilium.yaml.tpl", {
106-
operator_replica = local.operator_replica
107-
cluster_name = var.name
108-
cluster_id = var.cluster_id
109+
operator_replica = local.operator_replica
110+
cluster_name = var.name
111+
cluster_id = var.cluster_id
112+
ff_with_kubeproxy = var.ff_with_kubeproxy
109113
}),
110114
"patches/rke2-coredns.yaml" : templatefile("${path.module}/patches/rke2-coredns.yaml.tpl", {
111115
operator_replica = local.operator_replica
@@ -160,9 +164,14 @@ module "servers" {
160164
kube_scheduler_resources = var.kube_scheduler_resources
161165
kube_controller_manager_resources = var.kube_controller_manager_resources
162166
etcd_resources = var.etcd_resources
167+
kube_proxy_resources = var.kube_proxy_resources
163168

164169
ff_autoremove_agent = null
165170
ff_wait_ready = var.ff_wait_ready
171+
ff_with_kubeproxy = var.ff_with_kubeproxy
172+
173+
node_taints = each.value.node_taints
174+
node_labels = each.value.node_labels
166175
}
167176

168177
module "agents" {
@@ -202,12 +211,18 @@ module "agents" {
202211

203212
network_id = openstack_networking_network_v2.net.id
204213
subnet_id = openstack_networking_subnet_v2.agents.id
214+
cluster_cidr = var.cluster_cidr
215+
service_cidr = var.service_cidr
216+
cni = var.cni
205217
secgroup_id = openstack_networking_secgroup_v2.agent.id
206218
internal_vip = local.internal_vip
207219
vip_interface = var.vip_interface
208220
bastion_host = local.external_ip
209221

210222
ff_autoremove_agent = var.ff_autoremove_agent
211223
ff_wait_ready = var.ff_wait_ready
212-
224+
ff_with_kubeproxy = var.ff_with_kubeproxy
225+
226+
node_taints = each.value.node_taints
227+
node_labels = each.value.node_labels
213228
}

node/cloud-init.yaml.tpl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ write_files:
223223
server: "https://${internal_vip}:9345"
224224
%{~ endif ~}
225225
node-ip: "${node_ip}"
226+
cluster-cidr: "${cluster_cidr}"
227+
service-cidr: "${service_cidr}"
226228
cloud-provider-name: external
227229
advertise-address: "${node_ip}"
228230
write-kubeconfig-mode: "0640"
@@ -250,14 +252,19 @@ write_files:
250252
control-plane-resource-limits: "${control_plane_limits}"
251253
%{~ endif ~}
252254
disable-cloud-controller: true
253-
disable-kube-proxy: true
255+
disable-kube-proxy: ${ff_with_kubeproxy ? "false" : "true"}
254256
disable: rke2-ingress-nginx
255-
cni: cilium
256-
node-label:
257-
- node.kubernetes.io/exclude-from-external-load-balancers=true
257+
cni: "${cni}"
258258
node-taint:
259-
- CriticalAddonsOnly=true:NoExecute
260-
${indent(4,rke2_conf)}
259+
- CriticalAddonsOnly=true:NoExecute
260+
%{ for k, v in node_taints ~}
261+
- "${k}=${v}"
262+
%{ endfor ~}
263+
node-label:
264+
- node.kubernetes.io/exclude-from-external-load-balancers=true
265+
%{ for k, v in node_labels ~}
266+
- ${k}=${v}
267+
%{ endfor ~}
261268
%{~ else ~}
262269
- path: /etc/rancher/rke2/config.yaml
263270
permissions: "0600"
@@ -267,7 +274,14 @@ write_files:
267274
server: https://${internal_vip}:9345
268275
node-ip: ${node_ip}
269276
cloud-provider-name: external
270-
${indent(4,rke2_conf)}
277+
node-taint:
278+
%{ for k, v in node_taints ~}
279+
- "${k}=${v}"
280+
%{ endfor ~}
281+
node-label:
282+
%{ for k, v in node_labels ~}
283+
- "${k}=${v}"
284+
%{ endfor ~}
271285
%{~ endif ~}
272286

273287
runcmd:

node/main.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ resource "openstack_compute_instance_v2" "instance" {
8888
internal_vip = var.internal_vip
8989
vip_interface = var.vip_interface
9090
node_ip = openstack_networking_port_v2.port[count.index].all_fixed_ips[0]
91+
cluster_cidr = var.cluster_cidr
92+
service_cidr = var.service_cidr
93+
cni = var.cni
9194
san = var.is_server ? var.san : []
9295
manifests_files = var.is_server ? merge(
9396
var.manifests_folder != "" ? {
@@ -107,6 +110,8 @@ resource "openstack_compute_instance_v2" "instance" {
107110
try("kube-controller-manager-memory=${var.kube_controller_manager_resources.requests.memory}", ""),
108111
try("etcd-cpu=${var.etcd_resources.requests.cpu}", ""),
109112
try("etcd-memory=${var.etcd_resources.requests.memory}", ""),
113+
try("kube-proxy-cpu=${var.kube_proxy_resources.requests.cpu}", ""),
114+
try("kube-proxy-memory=${var.kube_proxy_resources.requests.memory}", ""),
110115
] : limit if limit != ""])
111116
control_plane_limits = join(",", [for limit in [
112117
try("kube-apiserver-cpu=${var.kube_apiserver_resources.limits.cpu}", ""),
@@ -117,10 +122,15 @@ resource "openstack_compute_instance_v2" "instance" {
117122
try("kube-controller-manager-memory=${var.kube_controller_manager_resources.limits.memory}", ""),
118123
try("etcd-cpu=${var.etcd_resources.limits.cpu}", ""),
119124
try("etcd-memory=${var.etcd_resources.limits.memory}", ""),
125+
try("kube-proxy-cpu=${var.kube_proxy_resources.limits.cpu}", ""),
126+
try("kube-proxy-memory=${var.kube_proxy_resources.limits.memory}", ""),
120127
] : limit if limit != ""])
121-
system_user = var.system_user
122-
authorized_keys = var.ssh_authorized_keys
123-
ff_wait_apiserver = false
128+
system_user = var.system_user
129+
authorized_keys = var.ssh_authorized_keys
130+
ff_wait_apiserver = false
131+
ff_with_kubeproxy = var.ff_with_kubeproxy
132+
node_taints = var.node_taints
133+
node_labels = var.node_labels
124134
}))
125135
}
126136

node/variables.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ variable "subnet_id" {
5959
type = string
6060
}
6161

62+
variable "cluster_cidr" {
63+
type = string
64+
}
65+
66+
variable "service_cidr" {
67+
type = string
68+
}
69+
70+
variable "cni" {
71+
type = string
72+
}
73+
6274
variable "san" {
6375
type = list(string)
6476
default = []
@@ -196,6 +208,20 @@ variable "etcd_resources" {
196208
default = null
197209
}
198210

211+
variable "kube_proxy_resources" {
212+
type = object({
213+
requests = optional(object({
214+
cpu = optional(string)
215+
memory = optional(string)
216+
}))
217+
limits = optional(object({
218+
cpu = optional(string)
219+
memory = optional(string)
220+
}))
221+
})
222+
default = null
223+
}
224+
199225
variable "manifests_folder" {
200226
type = string
201227
default = ""
@@ -218,3 +244,15 @@ variable "ff_wait_ready" {
218244
type = bool
219245
default = false
220246
}
247+
248+
variable "ff_with_kubeproxy" {
249+
type = bool
250+
}
251+
252+
variable "node_taints" {
253+
type = map(string)
254+
}
255+
256+
variable "node_labels" {
257+
type = map(string)
258+
}

patches/rke2-cilium.yaml.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cluster:
33
id: ${cluster_id}
44
eni:
55
enabled: true
6-
kubeProxyReplacement: "true"
6+
kubeProxyReplacement: "${ff_with_kubeproxy ? false : true}"
77
k8sServiceHost: 127.0.0.1
88
k8sServicePort: 6443
99
operator:

variables.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ variable "subnet_lb_cidr" {
8484
default = "192.168.44.0/24"
8585
}
8686

87+
variable "cluster_cidr" {
88+
type = string
89+
default = "10.42.0.0/16"
90+
}
91+
92+
variable "service_cidr" {
93+
type = string
94+
default = "10.43.0.0/16"
95+
}
96+
97+
variable "cni" {
98+
type = string
99+
default = "cilium"
100+
}
101+
87102
variable "vip_interface" {
88103
type = string
89104
default = "ens3"
@@ -127,6 +142,8 @@ variable "servers" {
127142
rke2_volume_size = number
128143
rke2_volume_type = optional(string)
129144
rke2_volume_device = optional(string)
145+
node_taints = optional(map(string), {})
146+
node_labels = optional(map(string), {})
130147
}))
131148
validation {
132149
condition = (
@@ -159,6 +176,8 @@ variable "agents" {
159176
rke2_volume_size = number
160177
rke2_volume_type = optional(string)
161178
rke2_volume_device = optional(string)
179+
node_taints = optional(map(string), {})
180+
node_labels = optional(map(string), {})
162181
}))
163182
validation {
164183
condition = (
@@ -249,6 +268,20 @@ variable "etcd_resources" {
249268
default = null
250269
}
251270

271+
variable "kube_proxy_resources" {
272+
type = object({
273+
requests = optional(object({
274+
cpu = optional(string)
275+
memory = optional(string)
276+
}))
277+
limits = optional(object({
278+
cpu = optional(string)
279+
memory = optional(string)
280+
}))
281+
})
282+
default = null
283+
}
284+
252285
variable "manifests_folder" {
253286
type = string
254287
default = ""
@@ -297,3 +330,8 @@ variable "ff_infomaniak_sc" {
297330
type = bool
298331
default = false
299332
}
333+
334+
variable "ff_with_kubeproxy" {
335+
type = bool
336+
default = false
337+
}

0 commit comments

Comments
 (0)