Skip to content

Commit

Permalink
add rpi nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Aug 12, 2024
1 parent b5ffded commit 7fbfffe
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 22 deletions.
1 change: 1 addition & 0 deletions modules/hetzner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
|------|-------------|------|---------|:--------:|
| <a name="input_firewall_allow_api_access"></a> [firewall\_allow\_api\_access](#input\_firewall\_allow\_api\_access) | CIDR range to allow access to the Kubernetes API | `list(string)` | <pre>[<br> "0.0.0.0/0",<br> "::/0"<br>]</pre> | no |
| <a name="input_firewall_allow_ssh_access"></a> [firewall\_allow\_ssh\_access](#input\_firewall\_allow\_ssh\_access) | CIDR range to allow access to the servers via SSH | `list(string)` | <pre>[<br> "0.0.0.0/0",<br> "::/0"<br>]</pre> | no |
| <a name="input_k3s_existing_worker_pools"></a> [k3s\_existing\_worker\_pools](#input\_k3s\_existing\_worker\_pools) | Additional workers on already existing nodes | <pre>map(list(object({<br> name = string<br> host = string<br> password = optional(string)<br> private_key = optional(string)<br> port = optional(number, 22)<br> user = string<br> })))</pre> | `{}` | no |
| <a name="input_k3s_manager_load_balancer_algorithm"></a> [k3s\_manager\_load\_balancer\_algorithm](#input\_k3s\_manager\_load\_balancer\_algorithm) | Algorithm to use for the k3s manager load balancer | `string` | `"round_robin"` | no |
| <a name="input_k3s_manager_load_balancer_type"></a> [k3s\_manager\_load\_balancer\_type](#input\_k3s\_manager\_load\_balancer\_type) | Load balancer type for the k3s manager nodes | `string` | `"lb11"` | no |
| <a name="input_k3s_manager_pool"></a> [k3s\_manager\_pool](#input\_k3s\_manager\_pool) | Manager pool configuration | <pre>object({<br> name = optional(string, "manager")<br> server_type = optional(string, "cx22")<br> count = optional(number, 1)<br> image = optional(string, "ubuntu-24.04")<br> })</pre> | `{}` | no |
Expand Down
45 changes: 32 additions & 13 deletions modules/hetzner/k3s.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ module "k3s" {
name = i.name
node-external-ip = i.ipv4_address
node-ip = tolist(i.network)[0].ip
labels = [
{
key = "provider"
value = "hetzner"
}
]

connection = {
host = i.ipv4_address
Expand All @@ -32,20 +38,33 @@ module "k3s" {
}
]

workers = {
for i, p in local.k3s_worker_pools : p.pool => {
name = hcloud_server.workers[i].name
node-external-ip = hcloud_server.workers[i].ipv4_address
node-ip = tolist(hcloud_server.workers[i].network)[0].ip
workers = merge(
{
for i, p in local.k3s_worker_pools : p.pool => {
name = hcloud_server.workers[i].name
node-external-ip = hcloud_server.workers[i].ipv4_address
node-ip = tolist(hcloud_server.workers[i].network)[0].ip
labels = lookup(p, "labels", [])

connection = {
host = hcloud_server.workers[i].ipv4_address
port = var.ssh_port
private_key = var.ssh_key
user = local.ssh_user
}
}...
}
connection = {
host = hcloud_server.workers[i].ipv4_address
port = var.ssh_port
private_key = var.ssh_key
user = local.ssh_user
}
}...
},
{
for p in local.k3s_additional_pools : p.pool => {
name = p.name
node-external-ip = p.connection.host
node-ip = p.connection.host
labels = lookup(p, "labels", [])

connection = p.connection
}...
}
)

disable_addons = [
"local-storage",
Expand Down
28 changes: 28 additions & 0 deletions modules/hetzner/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,38 @@ locals {
location = w.location != null ? w.location : var.location
name = "${w.name}-${n}"
pool = w.name
labels = [
{
key = "provider"
value = "hetzner"
}
]
}
)
]
])
k3s_additional_pools = flatten([
for poolName, nodes in var.k3s_existing_worker_pools : [
for i, n in nodes : {
name = lookup(n, "name", "${poolName}-${i}")
pool = poolName
labels = [
{
key = "provider"
value = "manual"
}
]

connection = {
host = n.host
password = n.password
port = n.port
private_key = n.private_key
user = n.user
}
}
]
])
kubernetes_api_port = 6443
labels = {
format(local.label_namespace, "project") = var.name
Expand Down
14 changes: 14 additions & 0 deletions modules/hetzner/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ variable "k3s_worker_pools" {
default = []
}

variable "k3s_existing_worker_pools" {
# sensitive = true
type = map(list(object({
name = string
host = string
password = optional(string)
private_key = optional(string)
port = optional(number, 22)
user = string
})))
description = "Additional workers on already existing nodes"
default = {}
}

variable "location" {
type = string
description = "Location to use. This is a single datacentre."
Expand Down
15 changes: 15 additions & 0 deletions modules/kubernetes/hetzner.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ resource "helm_release" "hcloud_ccm" {
value = sha512(yamlencode(kubernetes_secret_v1.hcloud.data))
}

set {
name = "nodeSelector.provider"
value = "hetzner"
}

depends_on = [kubernetes_secret_v1.hcloud]
}

Expand All @@ -69,6 +74,16 @@ resource "helm_release" "hcloud_csi" {
value = sha512(yamlencode(kubernetes_secret_v1.hcloud.data))
}

set {
name = "controller.nodeSelector.provider"
value = "hetzner"
}

set {
name = "node.nodeSelector.provider"
value = "hetzner"
}

# Allow running on control plane nodes
dynamic "set" {
for_each = flatten([
Expand Down
28 changes: 19 additions & 9 deletions stacks/dev/hetzner/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,27 @@ include {

inputs = {
k3s_manager_pool = {
count = 3
count = 1
}
k3s_worker_pools = [
{
count = 2
name = "pool1"
},
{
count = 1
name = "pool2"
}
// {
// count = 2
// name = "pool1"
// },
// {
// count = 1
// name = "pool2"
// }
]
k3s_existing_worker_pools = {
"pool1" : [
{
name = "homelab-001"
host = "192.168.1.243"
user = "homelab"
private_key = "@todo"
}
]
}
network_subnet = "10.2.0.0/16"
}

0 comments on commit 7fbfffe

Please sign in to comment.