OpenTofu – Load Balancer
Ein Load Balancer verteilt Anfragen auf die Control-Plane Nodes und ist Voraussetzung für eine HA-Installation. In diesem Tutorial wird HAProxy verwendet.
Hinweis zu --tls-san
Die IP-Adresse des Load Balancers muss in den TLS-SAN-Eintrag des Clusters aufgenommen werden, damit die Kubernetes-API über den Load Balancer erreichbar ist:
"curl -sfL https://get.k3s.io | ... sh -s - server --cluster-init --tls-san ${hcloud_server.load-balancer.ipv4_address}"
Befehle
cd ~/kubernetes-tutorial/src/opentofu/k3s-installation/k3s-installation-ha-load-balancer
tofu init
tofu plan
tofu apply
tofu state list
# IP des Load Balancers ermitteln
tofu state show hcloud_server.load-balancer | grep "ipv4_address"
# HAProxy Status prüfen
ssh -i ../../schulung root@[ip-load-balancer]
systemctl status haproxy
ls -lah /etc/haproxy/haproxy.cfg
exit
# HAProxy Konfiguration mit den Control-Plane IPs anpassen
scp -i ../../schulung haproxy.cfg root@[ip-load-balancer]:/etc/haproxy/haproxy.cfg
ssh -i ../../schulung root@[ip-load-balancer]
vim /etc/haproxy/haproxy.cfg # master-0, master-1, master-2 IPs eintragen
systemctl restart haproxy
exit
Cluster über Load Balancer erreichbar
# Healthcheck im Browser: http://[ip-load-balancer]/healthz
scp -i ../../schulung root@[ip-master-0]:/etc/rancher/k3s/k3s.yaml ~/.kube/config
# Zugriff über master-0 direkt
vim ~/.kube/config # server: https://[ip-master-0]:6443
kubectl get nodes
# Zugriff über master-1 direkt
vim ~/.kube/config # server: https://[ip-master-1]:6443
kubectl get nodes
# Zugriff über Load Balancer
vim ~/.kube/config # server: https://[ip-load-balancer]:6443
kubectl get nodes
tofu destroy