SSH to the nodes which will function as the load balancer and execute the following commands to install HAProxy.
1
apt update && apt install-y haproxy
Edit haproxy.cfg to connect it to the master nodes, set the correct values for <loadbalancer-vip> and <kube-masterX-ip> and add an extra entry for each additional master:
# Define the script used to check if haproxy is still working
vrrp_script chk_haproxy {
script "/usr/bin/killall -0 haproxy"
interval 2
weight 2
}# Configuration for Virtual Interface
vrrp_instance LB_VIP {
interface ens6
state MASTER # set to BACKUP on the peer machine
priority 301 # set to 300 on the peer machine
virtual_router_id 51
authentication {
auth_type user
auth_pass UGFzcwo=# Password for accessing vrrpd. Same on all devices}
unicast_src_ip <lb-master-ip> # IP address of master-lb
unicast_peer {
<lb-backup-ip> # IP address of the backup-lb}# The virtual ip address shared between the two loadbalancers
virtual_ipaddress {
<lb-vip> # vip }# Use the Defined Script to Check whether to initiate a fail over
track_script {
chk_haproxy
}}
# Define the script used to check if haproxy is still working
vrrp_script chk_haproxy {
script "/usr/bin/killall -0 haproxy"
interval 2
weight 2
}# Configuration for Virtual Interface
vrrp_instance LB_VIP {
interface ens6
state BACKUP # set to BACKUP on the peer machine
priority 300 # set to 301 on the peer machine
virtual_router_id 51
authentication {
auth_type user
auth_pass UGFzcwo=# Password for accessing vrrpd. Same on all devices}
unicast_src_ip <lb-backup-ip> #IP address of backup-lb
unicast_peer {
<lb-master-ip> #IP address of the master-lb}# The virtual ip address shared between the two loadbalancers
virtual_ipaddress {
<lb-vip> #vip}# Use the Defined Script to Check whether to initiate a fail over.
track_script {
chk_haproxy
}}