Skip to content

Commit f5de56d

Browse files
authored
Merge pull request #1695 from xavierleune/feature/private-ips-autoscaling
Feature: Disable public ips on autoscaled nodes
2 parents 2975302 + ebde425 commit f5de56d

File tree

8 files changed

+43
-6
lines changed

8 files changed

+43
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ If you follow this values, in your kube.tf, please set:
10151015
- `existing_network_id = [YOURID]` (with the brackets)
10161016
- `network_ipv4_cidr = "10.0.0.0/9"`
10171017
- Add `disable_ipv4 = true` and `disable_ipv6 = true` in all machines in all nodepools (control planes + agents).
1018+
- Add `autoscaler_disable_ipv4 = true` and `autoscaler_disable_ipv6 = true` to disable public ips on autoscaled nodes.
10181019

10191020
This setup is compatible with a loadbalancer for your control planes, however you should consider to set
10201021
`control_plane_lb_enable_public_interface = false` to keep ip private.

autoscaler-agents.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ locals {
4141
cluster_config = base64encode(jsonencode(local.cluster_config))
4242
firewall_id = hcloud_firewall.k3s.id
4343
cluster_name = local.cluster_prefix
44-
node_pools = var.autoscaler_nodepools
44+
node_pools = var.autoscaler_nodepools,
45+
disable_ipv4 = var.autoscaler_disable_ipv4,
46+
disable_ipv6 = var.autoscaler_disable_ipv6,
4547
})
4648
# A concatenated list of all autoscaled nodes
4749
autoscaled_nodes = length(var.autoscaler_nodepools) == 0 ? {} : {
@@ -116,7 +118,8 @@ data "cloudinit_config" "autoscaler_config" {
116118
})
117119
install_k3s_agent_script = join("\n", concat(local.install_k3s_agent, ["systemctl start k3s-agent"]))
118120
cloudinit_write_files_common = local.cloudinit_write_files_common
119-
cloudinit_runcmd_common = local.cloudinit_runcmd_common
121+
cloudinit_runcmd_common = local.cloudinit_runcmd_common,
122+
private_network_only = var.autoscaler_disable_ipv4 && var.autoscaler_disable_ipv6,
120123
}
121124
)
122125
}
@@ -150,7 +153,8 @@ data "cloudinit_config" "autoscaler_legacy_config" {
150153
})
151154
install_k3s_agent_script = join("\n", concat(local.install_k3s_agent, ["systemctl start k3s-agent"]))
152155
cloudinit_write_files_common = local.cloudinit_write_files_common
153-
cloudinit_runcmd_common = local.cloudinit_runcmd_common
156+
cloudinit_runcmd_common = local.cloudinit_runcmd_common,
157+
private_network_only = var.autoscaler_disable_ipv4 && var.autoscaler_disable_ipv6,
154158
}
155159
)
156160
}

kube.tf.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ module "kube-hetzner" {
360360
# # kubelet_args = ["kube-reserved=cpu=250m,memory=1500Mi,ephemeral-storage=1Gi", "system-reserved=cpu=250m,memory=300Mi"]
361361
# }
362362
# ]
363+
#
364+
# To disable public ips on your autoscaled nodes, uncomment the following lines:
365+
# autoscaler_disable_ipv4 = true
366+
# autoscaler_disable_ipv6 = true
363367

364368
# ⚠️ Deprecated, will be removed after a new Cluster Autoscaler version has been released which support the new way of setting labels and taints. See above.
365369
# Add extra labels on nodes started by the Cluster Autoscaler
@@ -1173,7 +1177,7 @@ terraform {
11731177
required_providers {
11741178
hcloud = {
11751179
source = "hetznercloud/hcloud"
1176-
version = ">= 1.49.1"
1180+
version = ">= 1.51.0"
11771181
}
11781182
}
11791183
}

modules/host/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
hcloud = {
44
source = "hetznercloud/hcloud"
5-
version = ">= 1.49.1"
5+
version = ">= 1.51.0"
66
}
77
}
88
}

templates/autoscaler-cloudinit.yaml.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,12 @@ runcmd:
4242

4343
${cloudinit_runcmd_common}
4444

45+
# Configure default route based on public ip availability
46+
%{if private_network_only~}
47+
- [ip, route, add, default, via, '10.0.0.1', dev, 'eth0']
48+
%{else~}
49+
- [ip, route, add, default, via, '172.31.1.1', dev, 'eth0']
50+
%{endif~}
51+
4552
# Start the install-k3s-agent service
4653
- ['/bin/bash', '/var/pre_install/install-k3s-agent.sh']

templates/autoscaler.yaml.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ spec:
194194
value: '${ipv4_subnet_id}'
195195
- name: HCLOUD_FIREWALL
196196
value: '${firewall_id}'
197+
%{~ if disable_ipv4 ~}
198+
- name: HCLOUD_PUBLIC_IPV4
199+
value: "false"
200+
%{~ endif ~}
201+
%{~ if disable_ipv6 ~}
202+
- name: HCLOUD_PUBLIC_IPV6
203+
value: "false"
204+
%{~ endif ~}
197205
%{~ if cluster_autoscaler_server_creation_timeout != "" ~}
198206
- name: HCLOUD_SERVER_CREATION_TIMEOUT
199207
value: '${cluster_autoscaler_server_creation_timeout}'

variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,19 @@ variable "autoscaler_taints" {
359359
default = []
360360
}
361361

362+
variable "autoscaler_disable_ipv4" {
363+
description = "Disable IPv4 on nodes created by the Cluster Autoscaler."
364+
type = bool
365+
default = false
366+
}
367+
368+
variable "autoscaler_disable_ipv6" {
369+
description = "Disable IPv6 on nodes created by the Cluster Autoscaler."
370+
type = bool
371+
default = false
372+
}
373+
374+
362375
variable "hetzner_ccm_version" {
363376
type = string
364377
default = null

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ terraform {
77
}
88
hcloud = {
99
source = "hetznercloud/hcloud"
10-
version = ">= 1.49.1"
10+
version = ">= 1.51.0"
1111
}
1212
local = {
1313
source = "hashicorp/local"

0 commit comments

Comments
 (0)