1) HAProxy Installation

HAProxy is an open-source proxy and load balancing solution used to provide high availability. Below is the installation guide for Ubuntu operating systems.


sudo apt update
sudo apt install haproxy
YML

The configuration file is edited.

sudo vi /etc/haproxy/haproxy.cfg
YML


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
POWERSHELL
systemctl enable haproxy && systemctl restart haproxy
systemctl status haproxy
POWERSHELL

1)Keepalived Installation

Keepalived typically provides a Virtual IP address among several control nodes (master and backup masters) and is used to ensure the continuous operation of other services.

sudo vim /etc/keepalived/check_apiserver.sh
POWERSHELL
#!/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
YML


chmod +x /etc/keepalived/check_apiserver.sh
POWERSHELL


Note: Add the appropriate network interface in the 'Interface' field.



sudo vim /etc/keepalived/keepalived.conf
POWERSHELL
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
    }
}
POWERSHELL



systemctl enable --now keepalived
POWERSHELL

Initializing Kubernetes Cluster


You can perform the Kubernetes installation using the document  Installation of Apinizer on Ubuntu OS 


Important: During the init process, you should enter your own virtual IP address as the endpoint.

kubeadm init --control-plane-endpoint="<VIRTUAL_IP>:6443" --upload-certs --pod-network-cidr=10.244.0.0/16
POWERSHELL