Skip to content

Commit

Permalink
Merge pull request #1001 from schlichtanders/load-balancer-create
Browse files Browse the repository at this point in the history
create cluster load balancer with terraform
  • Loading branch information
mysticaltech authored Oct 11, 2023
2 parents 4f0bddb + 9506c4c commit 2dfac3f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -760,11 +760,23 @@ module "kube-hetzner" {
etcd --version
etcdctl version
# delete traefik service so that no load-balancer is accidently changed
# start etcd server in the background
nohup etcd --data-dir /var/lib/rancher/k3s/server/db/etcd &
echo $! > save_pid.txt
# delete traefik service so that no load-balancer is accidently changed
etcdctl del /registry/services/specs/traefik/traefik
etcdctl del /registry/services/endpoints/traefik/traefik
# delete old nodes (they interfere with load balancer)
# minions is the old name for "nodes"
OLD_NODES=$(etcdctl get "" --prefix --keys-only | grep /registry/minions/ | cut -c 19-)
for NODE in $OLD_NODES; do
for KEY in $(etcdctl get "" --prefix --keys-only | grep $NODE); do
etcdctl del $KEY
done
done
kill -9 `cat save_pid.txt`
rm save_pid.txt
else
Expand Down
10 changes: 5 additions & 5 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ data "github_release" "calico" {
retrieve_by = "latest"
}

data "hcloud_load_balancer" "cluster" {
count = local.has_external_load_balancer ? 0 : 1
name = var.cluster_name
# data "hcloud_load_balancer" "cluster" {
# count = local.has_external_load_balancer ? 0 : 1
# name = var.cluster_name

depends_on = [null_resource.kustomization]
}
# depends_on = [null_resource.kustomization]
# }

data "hcloud_ssh_keys" "keys_by_selector" {
count = length(var.ssh_hcloud_key_label) > 0 ? 1 : 0
Expand Down
15 changes: 15 additions & 0 deletions init.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
resource "hcloud_load_balancer" "cluster" {
count = local.has_external_load_balancer ? 0 : 1
name = var.cluster_name

load_balancer_type = var.load_balancer_type
location = var.load_balancer_location
labels = local.labels

algorithm {
type = var.load_balancer_algorithm_type
}
}


resource "null_resource" "first_control_plane" {
connection {
user = "root"
Expand Down Expand Up @@ -305,6 +319,7 @@ resource "null_resource" "kustomization" {
}

depends_on = [
hcloud_load_balancer.cluster,
null_resource.first_control_plane,
random_password.rancher_bootstrap,
hcloud_volume.longhorn_volume
Expand Down
4 changes: 2 additions & 2 deletions output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ output "agents_public_ipv4" {

output "ingress_public_ipv4" {
description = "The public IPv4 address of the Hetzner load balancer"
value = local.has_external_load_balancer ? module.control_planes[keys(module.control_planes)[0]].ipv4_address : data.hcloud_load_balancer.cluster[0].ipv4
value = local.has_external_load_balancer ? module.control_planes[keys(module.control_planes)[0]].ipv4_address : hcloud_load_balancer.cluster[0].ipv4
}

output "ingress_public_ipv6" {
description = "The public IPv6 address of the Hetzner load balancer"
value = (local.has_external_load_balancer || var.load_balancer_disable_ipv6) ? null : data.hcloud_load_balancer.cluster[0].ipv6
value = (local.has_external_load_balancer || var.load_balancer_disable_ipv6) ? null : hcloud_load_balancer.cluster[0].ipv6
}

output "k3s_endpoint" {
Expand Down

0 comments on commit 2dfac3f

Please sign in to comment.