Skip to content

Commit

Permalink
autoscaling
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Jul 4, 2024
1 parent 46f3560 commit 5832cff
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 61 deletions.
2 changes: 1 addition & 1 deletion modules/hetzner/files/k3s-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ users:
lock_passwd: true
shell: /bin/bash
ssh_authorized_keys:
- "${publicKey}"
- "${chomp(publicKey)}"
write_files:
- path: /etc/ssh/sshd_config.d/ssh.conf
content: |
Expand Down
2 changes: 1 addition & 1 deletion modules/hetzner/files/k3s-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ users:
lock_passwd: true
shell: /bin/bash
ssh_authorized_keys:
- "${publicKey}"
- "${chomp(publicKey)}"
write_files:
- path: /etc/ssh/sshd_config.d/ssh.conf
content: |
Expand Down
58 changes: 27 additions & 31 deletions modules/hetzner/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,44 +59,40 @@ output "worker_pools" {
name = w.name
region = w.location != null ? w.location : var.location
}
config = {
imagesForArch = {
arm64 = "ubuntu-24.04"
amd64 = "ubuntu-24.04"
}
nodeConfigs = {
(w.name) = {
cloudInit = templatefile("${path.module}/files/k3s-worker.yaml", {
k3s_config = {
# node-label = [for l in w.labels : "${l.key}=${l.value}"]
# node-taint = [for t in local.k3s_worker_nodes[count.index].taints : "${t.key}=${t.value}:${t.effect}"]
server = local.k3s_server_url
token = local.k3s_join_token
}
k3s_download_url = var.k3s_download_url
sshPort = var.ssh_port
publicKey = hcloud_ssh_key.server.public_key
user = local.machine_user
})
labels = merge(
image = w.image,
cloudInit = base64encode(templatefile("${path.module}/files/k3s-worker.yaml", {
k3s_config = {
node-label = [for l in concat(
[
{
key = "node.kubernetes.io/role"
value = "autoscaler-node"
},
{
"node.kubernetes.io/role" = "autoscaler-node",
format(local.label_namespace, "pool") = w.name
key = format(local.label_namespace, "pool")
value = w.name
},
{ for l in w.labels : l.key => l.value }
)
taints = concat([
],
w.labels,
) : "${l.key}=${l.value}"]
node-taint = [for t in concat(
[
{
key = "node.kubernetes.io/role",
value = "autoscaler-node",
effect = "NoExecute"
}
],
w.taints,
)
}
},
],
w.taints,
) : "${t.key}=${t.value}:${t.effect}"]
server = local.k3s_server_url
token = local.k3s_join_token
}
}
k3s_download_url = var.k3s_download_url
sshPort = var.ssh_port
publicKey = hcloud_ssh_key.server.public_key
user = local.machine_user
}))
} if lookup(w.autoscaling, "enabled", false) == true
]
}
11 changes: 6 additions & 5 deletions modules/kubernetes/autoscaler.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ resource "kubernetes_secret_v1" "cluster_autoscaler" {
}

data = {
HCLOUD_TOKEN = var.hcloud_token
HCLOUD_NETWORK = var.hcloud_network_name
HCLOUD_FIREWALL = var.worker_pools[count.index].firewall_id
HCLOUD_SSH_KEY = var.worker_pools[count.index].ssh_key_id
HCLOUD_CLUSTER_CONFIG = base64encode(jsonencode(var.worker_pools[count.index].config))
HCLOUD_TOKEN = var.hcloud_token
HCLOUD_NETWORK = var.hcloud_network_name
HCLOUD_FIREWALL = var.worker_pools[count.index].firewall_id
HCLOUD_SSH_KEY = var.worker_pools[count.index].ssh_key_id
HCLOUD_CLOUD_INIT = base64encode(jsonencode(var.worker_pools[count.index].cloudInit))
HCLOUD_IMAGE = var.worker_pools[count.index].image
}
}

Expand Down
17 changes: 2 additions & 15 deletions modules/kubernetes/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,8 @@ variable "worker_pools" {
name = string
region = string
})
config = object({
imagesForArch = object({
arm64 = string
amd64 = string
})
nodeConfigs = map(object({
cloudInit = string
labels = map(string)
taints = list(object({
key = string
value = string
effect = string
}))
}))
})
image = string
cloudInit = string
}))
description = "Cluster autoscaler configuration"
# sensitive = true
Expand Down
19 changes: 11 additions & 8 deletions stacks/dev/hetzner/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ inputs = {
}
k3s_worker_pools = [
{
name = "pool1"
count = 0
// location = "fsn1"
name = "static"
count = 3
server_type = "cpx11"
// autoscaling = {
// enabled = true
// min = 1
// max = 3
// }
},
{
name = "scaling1"
server_type = "cpx11"
autoscaling = {
enabled = true
min = 1
max = 3
}
}
]
network_subnet = "10.2.0.0/16"
Expand Down

0 comments on commit 5832cff

Please sign in to comment.