Deploy a highly available Kubernetes cluster using Kubespray, Keepalived, and HAProxy. Our Live Support Team is always here to help you.
Setting Up High Availability Kubespray Keepalived HAProxy
If you’re building a Kubernetes cluster for production, availability isn’t just a nice-to-have, it’s mandatory. This is where the powerful trio of Kubespray Keepalived HAProxy comes in. Together, they help you run a highly available Kubernetes control plane without unnecessary complexity.
Here’s exactly how to put them to work.
An Overview
Environment Preparation
Before you start, make sure you have a clean set of servers ready. These will be your Kubernetes nodes, some acting as control plane (master) nodes, others as workers. Supported OS versions include Ubuntu, CentOS, and RHEL 8.
Each server should have:
- Internet connectivity
- A compatible Linux distro
- SSH access
You’ll also need a local system (your admin machine) with
- Python
- pip
- Git
- Ansible
Getting Kubespray
Start by cloning the Kubespray repo to your local machine:
git clone https://github.com/kubernetes-sigs/kubespray.git
cd kubespray
Defining Your Inventory
Kubespray relies on an inventory file to know which servers it should set up and what roles they’ll have. Below is a sample layout with two control plane nodes and two workers:
[all]
master-1 ansible_host=192.168.1.100
master-2 ansible_host=192.168.1.101
worker-1 ansible_host=192.168.1.102
worker-2 ansible_host=192.168.1.103
[kube-master]
master-1
master-2
[kube-node]
worker-1
worker-2
[etcd]
master-1
master-2
Save this as your inventory.ini file under inventory/sample/ or your custom folder.
Enabling Keepalived and HAProxy
Within the Kubespray directory, navigate to:
inventory/sample/group_vars
Here, create or edit k8s-cluster.yml to enable the use of Keepalived and HAProxy:
# File: inventory/sample/group_vars/k8s-cluster.yml
# Enable HAProxy as the load balancer for the Kubernetes API server
loadbalancer_apiserver: true
With this, Keepalived will manage a virtual IP address, and HAProxy will balance incoming traffic to your Kubernetes control plane nodes.
Running the Deployment
Now it’s time to trigger the actual deployment using Ansible. This command will start the automated Kubernetes setup based on your configuration:
ansible-playbook -i inventory/sample/inventory.ini cluster.yml
This playbook handles everything, from installing Kubernetes binaries to configuring HAProxy and Keepalived for a resilient API server.
Confirming the Setup
Once the deployment finishes, your cluster should be live with a highly available control plane:
- Keepalived is managing the virtual IP
- HAProxy is balancing traffic to API servers across control plane nodes
This ensures that even if one master goes down, your Kubernetes API remains accessible.
Optional Tweaks
Depending on your infrastructure, you might want to explore further settings around networking, firewall rules, and pod scheduling. The official Kubespray docs offer detailed configuration references if you want to fine-tune your cluster later.
Why Kubespray Keepalived HAProxy Setup Works
This setup is production-ready, battle-tested, and doesn’t require reinventing the wheel. The Kubespray Keepalived HAProxy stack is all about using proven tools the right way—no frills, no unnecessary complications.
You’re relying on:
- Kubespray for structured, repeatable deployments
- Keepalived for reliable failover with a floating IP
- HAProxy for intelligent traffic distribution
It’s one of the most robust architectures you can build with open-source tools, simple, solid, and scalable.
[If needed, Our team is available 24/7 for additional assistance.]
Conclusion
If you’re planning to run critical workloads on Kubernetes, don’t overlook high availability. With Kubespray Keepalived HAProxy, you’re not only simplifying the setup, you’re investing in long-term cluster stability.
Well, now it’s your turn to get your hands dirty and build a resilient Kubernetes environment and let the deployment begin.
0 Comments