How to Setup High-Availability Load Balancing with HAProxy & Keepalived
Configure redundant Active/Passive HAProxy load balancers with Keepalived VRRP floating Virtual IPs (VIP) on Ubuntu 24.04 to eliminate single points of failure.
Mohan Kumar BN
Senior Platform Engineer & CNCF Certified Kubestronaut
Eliminating Single Points of Failure for Kubernetes API Servers
A multi-master Kubernetes control plane is only as resilient as the load balancer sitting in front of port 6443. By combining Keepalived (using the VRRP protocol to manage a floating Virtual IP) with HAProxy (performing Layer-4 TCP health checks across control-plane nodes), we achieve sub-second automatic failover.
Configuration Breakdown
1. Keepalived Health Check & VRRP Configuration (/etc/keepalived/keepalived.conf)
vrrp_script check_apiserver {
script "/etc/keepalived/check_apiserver.sh"
interval 3
weight -2
fall 10
rise 2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101
authentication {
auth_type PASS
auth_pass K8sHaVipPass
}
virtual_ipaddress {
192.168.10.100/24
}
track_script {
check_apiserver
}
}
2. HAProxy Layer-4 Control Plane Frontend (/etc/haproxy/haproxy.cfg)
frontend kubernetes-frontend
bind *:6443
mode tcp
option tcplog
default_backend kubernetes-backend
backend kubernetes-backend
mode tcp
option tcp-check
balance roundrobin
server k8s-master-01 192.168.10.11:6443 check fall 3 rise 2
server k8s-master-02 192.168.10.12:6443 check fall 3 rise 2
server k8s-master-03 192.168.10.13:6443 check fall 3 rise 2 Related Engineering Blueprints
Install an External Ceph Distributed Storage Cluster Using Ansible
Provision a self-healing, multi-node Ceph distributed storage cluster with Ansible to deliver replicated block (RBD), shared file (CephFS), and object storage for Kubernetes.
Meet Longhorn: Cloud-Native Distributed Block Storage for Kubernetes
Deploy SUSE Longhorn on Kubernetes to provide synchronously replicated, self-healing persistent block volumes with automated snapshots and stateful workload resilience.
Deploy Self-Hosted Enterprise GitLab on Ubuntu with Ansible
Automate the deployment, TLS configuration, and day-2 tuning of a self-hosted GitLab instance on Ubuntu servers using idempotent Ansible playbooks.