- DO NOT USE THIS CONFIGURATION FOR PRODUCTION USE. THIS CONFIG IS FOR EDUCATIONAL PURPOSE ONLY
We need a floating IP for the loadbalance which will move across two LB nodes when ever there is a node failure. HA-Proxy will be running on both hosts and will take over new connections from the node once folating IP become active on that node. In this way, we will have a highly available LoadBalancer for Kubernetes API communication.
sudo apt-get install haproxy hatop
sudo sed -i -e "s/ENABLED=1/ENABLED=0/g" /etc/default/haproxy
sudo mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg-orig
- Configure HA-Proxy to pass traffic to controller VMs
sudo vi /etc/haproxy/haproxy.cfg
- Copy & paste below contents to the file
global
log /var/lib/haproxy/dev/log local0 debug
maxconn 2000
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
timeout connect 5000
timeout client 1000000000
timeout server 1000000000
frontend k8s-api
bind 192.168.78.220:6443
bind 127.0.0.1:6443
mode tcp
option tcplog
default_backend k8s-api
backend k8s-api
mode tcp
option tcplog
option tcp-check
balance source
default-server inter 600s downinter 5s rise 2 fall 2 slowstart 60s maxconn 250 maxqueue 256 weight 100
server controller-01 192.168.78.201:6443 check
server controller-02 192.168.78.202:6443 check
server controller-03 192.168.78.203:6443 check
sudo apt-get install keepalived
sudo bash -c 'echo "net.ipv4.ip_nonlocal_bind=1" >> /etc/sysctl.conf'
sudo sysctl -p
- Configure keepalived to for an HA floating IP
sudo vi /etc/keepalived/keepalived.conf
- Copy & paste below contents to the file
vrrp_script chk_haproxy {
script "killall -0 haproxy"
interval 2
weight 2
}
vrrp_instance VI_1 {
interface enp0s8
state MASTER
virtual_router_id 91
priority 101
virtual_ipaddress {
192.168.78.220/24
}
track_script {
chk_haproxy
}
}
- Start keepalived service
sudo service keepalived start
- Restart rsyslogd to start ha-proxy logging
sudo service rsyslog start
Part 3 - Install Client Tools