Kubernetes yüksek erişilebilirlik cluster kurulumunu gerçekleştirebilir. HAProxy ve Keepalived kullanarak çoklu master node yapılandırması yapabilir ve virtual IP adresi ile sürekli erişilebilirlik sağlayabilir.
sudo apt update
sudo apt install haproxy
sudo vi /etc/haproxy/haproxy.cfg
frontend kubernetes-frontend
bind *:6443
mode tcp
option tcplog
default_backend kubernetes-backend
backend kubernetes-backend
option httpchk GET /healthz
http-check expect status 200
mode tcp
option ssl-hello-chk
balance roundrobin
server <master1hostname> <MASTER_1_IP>:6443 check fall 3 rise 2
server <master2hostname> <MASTER_2_IP>:6443 check fall 3 rise 2
server <master3hostname> <MASTER_3_IP>:6443 check fall 3 rise 2
systemctl enable haproxy && systemctl restart haproxy
systemctl status haproxy
sudo apt install keepalived
sudo vim /etc/keepalived/check_apiserver.sh
#!/bin/sh
errorExit() {
echo "*** $@" 1>&2
exit 1
}
curl --silent --max-time 2 --insecure https://localhost:6443/ -o /dev/null || errorExit "Error GET https://localhost:6443/"
if ip addr | grep -q <VIRTUAL_IP>; then
curl --silent --max-time 2 --insecure https://<VIRTUAL_IP>:6443/ -o /dev/null || errorExit "Error GET https://<VIRTUAL_IP>:6443/"
fi
chmod +x /etc/keepalived/check_apiserver.sh
sudo vim /etc/keepalived/keepalived.conf
vrrp_script check_apiserver {
script "/etc/keepalived/check_apiserver.sh"
interval 3
timeout 10
fall 5
rise 2
weight -2
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 1
priority 100
advert_int 5
authentication {
auth_type PASS
auth_pass mysecret
}
virtual_ipaddress {
<VIRTUAL_IP>
}
track_script {
check_apiserver
}
}
systemctl enable --now keepalived
kubeadm init --control-plane-endpoint="<VIRTUAL_IP>:6443" --upload-certs --pod-network-cidr=10.244.0.0/16