Kubernetes API load balancing with keepalived, HAProxy or kube-vip

Give your highly available Kubernetes control plane one stable endpoint on infrastructure you control, with a load balancer design that does not become the outage.

On this page

Why a Kubernetes API load balancer decides whether your HA control plane is really HA

If you have or plan three or more control plane nodes on-premises, the decision that determines whether that design is genuinely highly available is how you give kubectl, kubelets and controllers one stable address for the API server. The kubeadm high availability guidance expects a TCP load balancer in front of kube-apiserver listening on port 6443, spread across at least three control plane nodes. Keepalived with HAProxy, or kube-vip, can supply that endpoint on your own network, and each option carries different constraints on virtual IP placement, health checking and failover behavior. Pick the option before you bootstrap the first node, because kubeadm writes the control plane endpoint into certificates and kubeconfig files during init.

The load balancer layer must not become the single point of failure you were trying to remove. A single HAProxy instance in front of three healthy API servers still produces an outage when that one proxy host fails, so the endpoint itself needs redundancy: either a floating virtual IP that moves between two or more hosts, or a pair of balancers reached through a shared address. Confirm with your network team which subnet the virtual IP must sit in, whether your switches and gateways allow gratuitous ARP for failover, and whether your hypervisor or bare-metal platform permits the address to move between nodes. A virtual IP that cannot leave its subnet or be claimed by another host will not fail over at all.

Health checks decide how quickly traffic leaves a failed API server. A TCP check on port 6443 confirms that something is listening, but an HTTPS check against the API server health endpoint is a stronger signal that the server is serving requests. Ask for the check interval, failure threshold and recovery threshold you intend to use, and test them by stopping kube-apiserver on one node during a maintenance window. Also confirm that your etcd members stay healthy on the same nodes, because an API server that answers health checks while etcd has lost quorum still cannot serve writes.

Choosing between keepalived with HAProxy, kube-vip and a hardware or cloud load balancer

This table compares four ways to give a highly available control plane one stable endpoint on port 6443, covering where the endpoint lives, how it fails, who operates it and what it assumes about the network. Read each row against your own network and team, and treat the last row as the main decision point. No single option fits every environment, so confirm the open items before you choose.

Decision factorkeepalived with HAProxykube-vipHardware or cloud load balancer
Where the endpoint livesVirtual IP on control plane or dedicated load balancer nodes, with HAProxy forwarding TCP to kube-apiserverVirtual IP advertised from control plane nodes, with leader election inside the clusterAppliance or managed service outside the cluster, with its own address
Failure behaviorkeepalived moves the virtual IP on failure; HAProxy health checks drop unhealthy backends on port 6443Leader moves the virtual IP after lease expiry; failover depends on the cluster's own control plane healthFailover depends on vendor or provider health checks and configuration; confirm failover times in writing
Who operates itYour platform team, managing packages, configuration and patching on separate hostsYour platform team, managing a manifest or static pod that must stay in step with cluster upgradesNetwork or cloud team, under a contract or service agreement that defines support
Layer 2 or subnet dependenceRequires the virtual IP to sit on a subnet the nodes share and that the VRRP traffic can crossTypically requires nodes on one layer 2 segment for ARP-based advertisement; confirm the mode your network supportsUsually routed; no virtual IP on your nodes, but the appliance needs reachability to every control plane node
Fit with stacked etcdWorks well; the load balancer is separate from etcd members, but do not co-locate both on the same two hostsNatural fit, since the endpoint lives on the same nodes as the control plane, so a single node loss moves the endpoint with itWorks well, and keeps the endpoint independent of control plane nodes
Fit with external etcdWorks well; keep load balancer hosts separate from etcd and control plane hosts where possibleWorks, but the endpoint still depends on the control plane nodes, so confirm the design before choosing itWorks well; a common choice where the network team already runs load balancing
When it fitsOn-premises clusters where the team can run two or more small load balancer hosts and wants full control of configurationSmaller on-premises clusters with a flat network, where fewer moving parts matter more than separate load balancer hostsOrganizations that already run supported appliances or cloud load balancers and need contracted support
What to confirm firstWhether VRRP is permitted between hosts, how many load balancer hosts you can dedicate, and who patches themWhether your switches and security policy allow the advertisement mode you need and how upgrades will update the manifestHealth check support on port 6443, failover behavior, supported TLS passthrough and who owns incidents

Subnet and network constraints for a virtual IP on-premises

A virtual IP gives the API server one stable address, but it only works if the network lets that address move between control plane nodes. The cards below cover the constraints that most often stall an on-premises rollout, and each one has a check to run before the first node joins.

Keep the VIP in the node subnet

The virtual IP must sit in the same subnet as the control plane nodes that will hold it, because keepalived, kube-vip and similar tools move the address between hosts on one network segment. Choose an unused address inside that range and record it as the cluster endpoint before running kubeadm init. If the VIP falls outside the node subnet, failover will fail silently when the active node goes down.

kubeadm HA guide

Confirm layer 2 adjacency and ARP

Most VRRP-based setups announce the VIP with gratuitous ARP, which only reaches hosts on the same layer 2 domain. Ask the network team whether the control plane nodes share a broadcast domain, whether switches or hypervisor virtual networks suppress or filter gratuitous ARP, and whether the router caches MAC addresses for long periods. Where layer 2 is not available, confirm whether the platform supports a routed alternative such as BGP.

Reserve the address from DHCP

The VIP must not be handed to any other device by DHCP or be used as a static address on another host. A duplicate address causes intermittent API timeouts that look like load balancer faults. Ask the network team to exclude the VIP and the node addresses from the DHCP scope, and to confirm that IPAM or the hypervisor will not reassign it.

Open VRRP and election traffic

keepalived uses VRRP, which is IP protocol 112 and not TCP or UDP, so a firewall rule written only for ports will block failover. kube-vip uses its own leader election traffic over the cluster network. Confirm that host firewalls, security groups and switch ACLs allow this traffic between control plane nodes, and that the rules survive a node reboot.

Allow API traffic on port 6443

Clients, worker kubelets and the other control plane nodes all reach the API server through the VIP on port 6443. The load balancer health check must test that port, and firewall rules must allow it from every workstation, CI runner and node subnet that talks to the cluster. Ask the network team to list every source network, including monitoring and backup systems, before the rules go live.

Plan for multi-site or split subnets

If control plane nodes sit in different racks, rooms or data centers, a single VIP on one subnet may not reach all of them. Stretched layer 2 links can introduce latency and split-brain risk, so confirm with the network team which failures the design must survive. Record the answer in the runbook, because it determines whether the VIP model is suitable at all.

Setting up a single API endpoint for three control plane nodes

This sequence gives three control plane nodes one stable address for kube-apiserver, so kubectl, kubelets and joining nodes keep working when a single control plane node fails. Each step ends with a check you can confirm before moving on.

  1. Reserve the virtual IP and DNS name

    The network team, or the platform engineer with access to the subnet, reserves one unused IP address in the same Layer 2 subnet as the three control plane nodes and creates a DNS record such as k8s-api.example.internal that points to it. Confirm that the VIP is not assigned by DHCP, that it is not in use (a ping from another host should get no reply), and that the three control plane nodes resolve the name to the VIP. Keepalived and kube-vip both advertise the VIP on the local segment, so a VIP outside the nodes' subnet will not fail over. Record the VIP, the DNS name and the subnet in your build notes, because the kubeadm endpoint depends on them.

  2. Install and configure the load balancer or VIP service

    On each control plane node, or on a dedicated pair of load balancer nodes, install the chosen component: keepalived with HAProxy for a separate TCP proxy and floating VIP, or kube-vip for a VIP that runs as a static pod. Give each instance a unique priority or leader setting, set the same virtual router ID and authentication secret across the group, and bind the VIP to the correct interface. Check that the service starts on every node, that exactly one node holds the VIP (for example, with ip addr show on each node), and that the VIP moves when the current holder's service is stopped. If you use a dedicated pair, the pair itself becomes part of the availability design, so plan it deliberately.

  3. Configure TCP health checks against port 6443

    Point the HAProxy frontend at TCP port 6443 and define a backend with one server entry for each control plane node's kube-apiserver. Use TCP health checks that remove a backend from rotation when port 6443 stops answering. If you use kube-vip, confirm that its ARP or BGP mode and leader election behave as expected for your network. Before you rely on the endpoint, test it from a workstation with curl -k https://<VIP>:6443/readyz or kubectl once a control plane exists, and confirm that the proxy's stats page or logs show each backend's state. Note that a TCP check only proves the port is open, so readiness of the API server should be confirmed separately during verification.

  4. Set the endpoint before the first kubeadm init

    Run kubeadm init on the first control plane node with --control-plane-endpoint set to the DNS name and port, for example k8s-api.example.internal:6443, and add --upload-certs if you will join the other control plane nodes from that same run. The endpoint is written into the cluster certificates and kubeconfig files, so it must be right before the first init. Changing it afterward means regenerating certificates and updating kubeconfigs, which is far more work than getting it right now. Confirm that the generated admin kubeconfig points to the DNS name and that the API server certificate includes that name in its subject alternative names.

  5. Join the remaining control plane nodes

    On the second and third control plane nodes, run the kubeadm join command with the control plane flag, the same control-plane endpoint, the bootstrap token, the discovery hash and the certificate key printed by the first init. Each join should complete without errors. Afterward, run kubectl get nodes and kubectl get pods -n kube-system to confirm that all three control plane nodes are Ready and that the etcd and kube-apiserver static pods are running on each. Confirm that all three nodes appear as control plane members before you add workers.

  6. Verify failover by stopping a control plane node

    Choose one control plane node that does not hold the VIP, check the endpoint from a workstation, and then stop kube-apiserver on the node that holds the VIP, or power it off, while running a steady kubectl get nodes loop. Confirm that the VIP moves to another node, that the loop recovers within the window your change record allows, and that the cluster still reports the remaining control plane nodes as healthy. Then restart the node and confirm it rejoins the VIP group without reclaiming the endpoint unexpectedly, depending on your priority settings. Repeat the test for each node if your change process requires it, and record the observed behavior in the runbook.

  7. Avoid a single load balancer becoming the outage

    Confirm that the load balancer layer does not reintroduce a single point of failure. If keepalived and HAProxy run on the three control plane nodes, a single node loss removes one proxy and moves the VIP, which is the failure the design expects. If they run on a dedicated pair, the pair needs its own failover test and its own monitoring, and a single host outage should still leave a working VIP. Document which failures the design survives, such as one node or one proxy process, and which it does not, such as loss of the subnet switch or both VIP holders. Check monitoring for VIP ownership and backend health so that a failed proxy is seen before the next failure occurs.

How client requests reach the API servers through the virtual endpoint

Requests start at kubectl, kubelets and controllers, which resolve the cluster DNS name to a single virtual IP. The current VIP holder, or the active HAProxy instance, accepts TCP traffic on port 6443 and forwards it to healthy kube-apiserver instances on the three control plane nodes. Each kube-apiserver reads and writes cluster state in the etcd members behind it. The failure path shows the active node failing, the VIP or backend moving to a surviving node, and clients reconnecting to the same name. Check that health checks remove the failed backend before traffic resumes.

Clients reach three API servers through one endpoint, and a standby takes over on failure.

Keeping the load balancer from becoming the single point of failure

An HA control plane is only as available as the address clients use to reach it. The cards below cover the design choices that keep the endpoint layer from failing together with the API servers, and they depend on your network, hypervisor and failure domain layout, so results will vary by environment.

Run more than one balancer instance

A single HAProxy or keepalived node in front of three API servers recreates the outage you were trying to avoid. Run at least two balancer instances, each able to serve port 6443 to every control plane node, so losing one host leaves the endpoint reachable. Confirm that both instances can reach all API server addresses before you cut over client kubeconfig files.

kubeadm HA guide

Health checks that remove dead backends

The balancer should probe each kube-apiserver on port 6443 and stop routing to any backend that fails the check. A TCP check only proves the port is open, so a hung API server can still receive traffic. Ask your team to test an HTTPS health endpoint that reflects API server readiness, and to confirm the check interval and failure threshold in writing.

Separate balancer and control plane failure domains

Where practical, place balancer instances on hosts or hypervisors that do not share a failure domain with the control plane nodes they front. A balancer co-located on the same physical host as an API server can fail with it. Map each balancer to a rack, power feed or hypervisor host and check that no single host failure removes both the endpoint and a quorum member.

Monitor the VIP holder

With keepalived or kube-vip, one node holds the virtual IP at any time, and failover is only as good as the signal that triggers it. Alert on which node holds the VIP, on unexpected VIP moves, and on the state of the health check script itself. Watch for flapping, since repeated failovers can disrupt long-lived client connections and kubelet traffic.

Test failover on a schedule

An endpoint that has never been failed over is an untested assumption. Stop the active balancer, drop a backend API server and fail the VIP holder on a non-production cluster, then record how long clients take to recover and whether kubectl and node heartbeats resume. Repeat the tests after each change to network, certificates or balancer configuration, and ask your partner to include them in the delivered runbook.

Choose the balancer for your network

keepalived with HAProxy, and kube-vip, each solve the same problem in different ways, so the choice depends on what your network allows. Confirm whether your subnet permits a floating virtual IP, whether gratuitous ARP is honored by your switches, and whether your team already operates keepalived. Record the decision and its reason so later upgrades do not silently change the design.

Questions teams ask before building the control plane endpoint

Is a load balancer required for a highly available Kubernetes control plane?

Yes, if you run more than one kube-apiserver and want clients to reach one stable address. The kubeadm high availability guide places a TCP load balancer in front of kube-apiserver on port 6443 and expects at least three control plane nodes. Without it, kubectl, kubelets and controllers must each know a specific node address, and a failed node breaks their connections until someone reconfigures them. The load balancer does not need to be a separate server, since keepalived, HAProxy or kube-vip can all be placed on the control plane nodes themselves, but something must provide the single endpoint and health-check the members behind it.

Which option should we choose for an on-premises control plane endpoint?

The choice depends on whether your network lets you own a floating virtual IP and how much you want to operate. keepalived gives you a virtual IP that moves between nodes using VRRP, and it is common when you control Layer 2 and can reserve an address. HAProxy handles TCP balancing and health checks well, and is usually paired with keepalived so the balancer itself does not become a single point of failure. kube-vip can provide a virtual IP and control plane load balancing from within the cluster, which reduces the number of components but adds a dependency on the cluster it serves. Decide with your network team, then test failover on the exact switches and hypervisors you run.

How does the effort change with our network access and team skills?

Effort rises with the number of network boundaries the endpoint must cross. A single flat subnet where you can reserve a virtual IP is the simplest case. Separate VLANs, firewalls between control plane and admin networks, cloud subnets that block gratuitous ARP or multicast, and load balancers that already exist in your data center all add review, rule changes and testing. Team skills matter as much: someone must own keepalived priorities, HAProxy configuration, certificate SANs and failover drills. Ask for the work to list each network path that must be opened on port 6443 and who approves the change.

What do we need to provide before the work starts?

The work depends on information only your organization can supply. Expect to provide the planned control plane node addresses, a reserved virtual IP and DNS name for the API endpoint, the subnet and VLAN layout, firewall and routing change approvals, the hypervisor or bare-metal platform, and a decision on who receives access to the load balancer configuration. You will also need the certificate authority approach, because the API server certificate must include the endpoint name and addresses clients use. A written scope should list each of these items and the owner for each.

Can our internal team build and run this endpoint alone?

Often yes, if at least one engineer has operated Linux networking, TLS and a cluster before, and the team can test failover outside production. The risky parts are rarely the initial configuration. They are the failure drills, the upgrade of each control plane node in turn, and the moment a load balancer config change accidentally removes a healthy backend. Ask any partner to show how they test a node loss, a balancer restart and a split network before go-live, and confirm whether the handover includes a runbook your team can execute without the original author.

How does the endpoint behave during upgrades and certificate renewal?

The endpoint should stay constant while individual control plane nodes change. During a kube-apiserver upgrade, drain the node from the balancer pool, upgrade it, confirm the health check on port 6443 passes, then return it to the pool before moving to the next node. The version skew policy requires kube-apiserver to move one minor version at a time, so plan the sequence before starting. Certificate renewal is different: the API server certificate must still list the virtual IP and DNS name after renewal, and any HAProxy or kube-vip TLS passthrough settings must not change the client trust path. Confirm the renewal procedure in a non-production copy first.

How can the load balancer itself avoid becoming the outage?

Run the balancing layer redundantly, and make each node able to take over without manual action. Keepalived with a second node, HAProxy on each control plane host, or kube-vip with leader election all remove a single balancer host from the path. Test what happens when the active balancer is stopped, when the health check fails on one API server, and when the network partitions. Monitor the virtual IP owner and each backend, and alert when the pool drops below the number of healthy control plane nodes. Also keep a documented way to reach the nodes directly if the virtual IP fails.

How DeployOpen designs and tests the API endpoint

DeployOpen scopes the Kubernetes API endpoint as part of the wider control plane design, then builds and tests it inside your own network. The written scope fixes the load balancer choice, virtual IP plan, health checks and failure tests before any change reaches a production cluster.

How we scope

  • Written scope records the chosen option (keepalived with HAProxy, or kube-vip) and the reasons for it.
  • We map the subnet, the virtual IP address and the control plane node addresses your network allows.
  • The scope names who owns DNS, firewall rules and the health check path on port 6443.

How we build

  • We configure the endpoint on each control plane node and confirm the virtual IP moves between nodes during controlled failover.
  • Health checks against kube-apiserver on port 6443 are tested with a node stopped, not only with the service running.
  • We remove any single load balancer from the design so one component cannot become the outage.

How we hand over

  • Deliverables include configuration files, the failover test results and a runbook for changing the endpoint.
  • Documentation covers certificate SANs for the virtual IP or DNS name, so kubeadm and clients trust the endpoint.
  • Your team receives a walkthrough of failover tests so operators can repeat them after changes.

How we support

  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer, including retesting after control plane changes.
  • Ask us to confirm how upgrades of the load balancer packages will be tested against your Kubernetes version plan.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.