Skip to content
LF Cert Trainer

Lesson 128 · Section 10: Cluster Installation & High Availability

Lesson 128: High availability control plane: how three nodes act as one

Why a control plane needs more than one node, how each component behaves when there are several (API servers behind a load balancer, a leader for the scheduler and controller manager, etcd quorum), and how to choose between stacked and external etcd. · 18 min read · 3 min video

1/9High availability control plane
0:00 / 2:51

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

Why it exists

The control plane is the cluster's brain. When its only node goes down, the running containers keep running, because the kubelets on the workers already have their Pods. Everything else stops:

  • kubectl gets connection refused, and so does every CI pipeline.
  • No new Pod is scheduled, no Deployment rolls out, no HorizontalPodAutoscaler scales.
  • A worker that dies is never noticed, so its Pods are never replaced elsewhere.

For a lab that is fine. For production it means any OS patch on the control plane is an outage window. A highly available (HA) control plane runs every control plane component on several nodes, so that one node can fail, or be drained for an upgrade, without anyone noticing.

Three control plane nodes behind one addresshttpshttpskubectladminWorker kubeletsnode01..node03Load balancerk8s-api:6443controlplane1API servercontrolplane2API servercontrolplane3API serveretcd cluster3 members, 1 leader
Three control plane nodes behind one address. Workers, kubectl and the control plane's own components all use the load balancer's address. Any healthy API server can answer, so losing one node changes nothing for clients.

Parts:

  • kubectl (admin)
  • Worker kubelets (node01..node03)
  • Load balancer (k8s-api:6443)
  • controlplane1 (API server)
  • controlplane2 (API server)
  • controlplane3 (API server)
  • etcd cluster (3 members, 1 leader)

Connections:

  • kubectl to Load balancer: https
  • Worker kubelets to Load balancer: https
  • Load balancer to controlplane1
  • Load balancer to controlplane2
  • Load balancer to controlplane3
  • controlplane1 to etcd cluster
  • controlplane2 to etcd cluster
  • controlplane3 to etcd cluster

What it is

PartHow manyHow they share the work
Load balancer (or virtual IP)1 address, ideally itself redundantSpreads TCP connections on port 6443 over the healthy API servers
kube-apiserverOne per control plane nodeActive-active: every instance serves requests; they keep no state of their own
kube-schedulerOne per control plane nodeActive-standby: one leader schedules, the others wait
kube-controller-managerOne per control plane nodeActive-standby, the same way
etcd3 or 5 membersA Raft cluster: one leader orders writes, a majority must agree
kubelet, kube-proxyOn every node, as beforeTalk to the load balancer address instead of one node

The stable address

Everything that talks to the API server, worker kubelets, kube-proxy, kubectl, uses a single address: the control plane endpoint. In kubeadm it is the --control-plane-endpoint flag (or controlPlaneEndpoint in the config file), usually a DNS name such as k8s-api.example.internal:6443 that points at a load balancer. kubeadm writes this address into every kubeconfig file and into the API server's certificate, so that the certificate is valid whichever node answers.

That is why it must be chosen at kubeadm init. A cluster built with one node's own IP baked into every kubeconfig cannot be made HA by kubeadm later.

How it works

Active-active, and active-standbyrenewsrenewsreads, writeskube-apiserverall 3 servekube-scheduler1 leader, 2 waitcontroller-manager1 leader, 2 waitLease objectskube-systemetcdRaft leader
Active-active, and active-standby. API servers are stateless and all serve at once. The scheduler and controller manager run on every node, but only the holder of a Lease acts; the others wait to take over. etcd elects a leader that orders every write.

Parts:

  • kube-apiserver (all 3 serve)
  • kube-scheduler (1 leader, 2 wait)
  • controller-manager (1 leader, 2 wait)
  • Lease objects (kube-system)
  • etcd (Raft leader)

Connections:

  • kube-scheduler to Lease objects: renews
  • controller-manager to Lease objects: renews
  • kube-apiserver to etcd: reads, writes

API servers: all of them at once

The API server is a front end for etcd: it authenticates, authorizes, validates and then stores. It holds no state between requests, so three of them can serve at the same time without coordinating. The load balancer sends each new connection to any healthy one. A watch held open by a kubelet stays on one API server; if that server dies, the kubelet reconnects through the load balancer and lands on another.

Scheduler and controller manager: one leader through a Lease

Two schedulers deciding the same Pod at the same moment would be a mess, so these components elect a leader. Each instance tries to take a Lease object in kube-system (kube-scheduler, kube-controller-manager). The holder writes its identity and renews the Lease every few seconds. The others watch it; if the renew time gets too old (about 15 seconds by default), one of them takes over.

kubectl -n kube-system get lease kube-scheduler -o jsonpath='{.spec.holderIdentity}{"\n"}'
controlplane2_5c1e9a0b-6f1e-4a8d-9a0e-2b8f1d3c7e55

The leader is on controlplane2. The scheduler Pods on the other two nodes are Running and look healthy; they are just waiting. This is the --leader-elect=true flag you see in their static Pod manifests.

etcd: a majority, or nothing

etcd uses the Raft consensus algorithm. Members elect a leader; every write goes through the leader and counts as committed only when a majority (the quorum) has stored it. A member that cannot reach a majority stops accepting writes, which protects the data from two halves of a split network each going their own way.

MembersMajority (quorum)Can lose
110
220
321
431
532
743

The rule is majority = floor(members / 2) + 1. Adding a fourth member raises the majority to 3 without letting you lose more members, so even counts only add cost. More than 5 or 7 members makes every write slower, because more members must confirm it.

Types: stacked or external etcd

Stacked etcd or external etcdStacked: 3 machinesExternal: 6 machinesCP + etcdnode 1CP + etcdnode 2CP + etcdnode 3Control plane3 nodesetcdnode 4etcdnode 5etcdnode 6
Stacked etcd or external etcd. Stacked: each control plane node also runs an etcd member, so 3 machines do everything. External: etcd has its own 3 machines, so losing a control plane node costs no etcd member, at twice the machines.

Parts:

  • CP + etcd (node 1), in Stacked: 3 machines
  • CP + etcd (node 2), in Stacked: 3 machines
  • CP + etcd (node 3), in Stacked: 3 machines
  • Control plane (3 nodes), in External: 6 machines
  • etcd (node 4), in External: 6 machines
  • etcd (node 5), in External: 6 machines
  • etcd (node 6), in External: 6 machines

Connections:

  • Control plane to etcd
  • Control plane to etcd
  • Control plane to etcd
Stacked etcdExternal etcd
Where etcd runsA member on each control plane node, as a static PodOn its own machines
Machines for HA36 (3 control plane + 3 etcd)
Set up bykubeadm, automatically (kubeadm init, kubeadm join --control-plane)You (or kubeadm on each etcd host), then point kubeadm at it
Losing one control plane node costsAn API server and an etcd memberOnly an API server
kubeadm defaultYesNo
Good forMost clustersLarge clusters, or where etcd needs its own disks and care

In the stacked layout, each API server talks to the etcd member on its own node (--etcd-servers=https://127.0.0.1:2379). In the external layout, each API server lists every etcd member, and uses a client certificate to reach them.

Under the hood · What the load balancer has to do

The load balancer is plain TCP: it forwards port 6443 and does not terminate TLS, because the API server's own certificate (with the endpoint name in it) must reach the client. It should health check each API server, for example with an HTTPS GET on /livez, so that a node being restarted drops out.

Common choices:

  • HAProxy (often with keepalived for a floating virtual IP) on two small machines of its own.
  • kube-vip as a static Pod on the control plane nodes themselves, holding a virtual IP that moves to a healthy node.
  • A cloud load balancer in front of the three VMs.

The load balancer itself must not become the new single point of failure, which is why the HAProxy setups come in pairs and kube-vip moves its address between nodes.

Using it

Example · Find out whether a cluster is HA, and who leads

Count the control plane nodes:

kubectl get nodes -l node-role.kubernetes.io/control-plane
NAME            STATUS   ROLES           AGE   VERSION
controlplane1   Ready    control-plane   3d    v1.37.0
controlplane2   Ready    control-plane   3d    v1.37.0
controlplane3   Ready    control-plane   3d    v1.37.0

Read the endpoint that every client uses:

kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}{"\n"}'
kubectl -n kube-system get cm kubeadm-config -o yaml | grep controlPlaneEndpoint
https://k8s-api.lab.internal:6443
    controlPlaneEndpoint: k8s-api.lab.internal:6443

And the two leaders:

kubectl -n kube-system get lease kube-scheduler kube-controller-manager \
  -o custom-columns=NAME:.metadata.name,LEADER:.spec.holderIdentity
NAME                      LEADER
kube-scheduler            controlplane2_5c1e9a0b-6f1e-4a8d-9a0e-2b8f1d3c7e55
kube-controller-manager   controlplane1_8d7f2c41-0b6e-4c1a-a2f3-9e1d7c5b0a12

Example · List the etcd members and their leader

On a stacked cluster, run etcdctl inside any etcd Pod, with the certificates kubeadm created:

kubectl -n kube-system exec etcd-controlplane1 -- etcdctl \
  --endpoints=https://127.0.0.1:2379 \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  endpoint status --cluster -w table
+----------------------------+------------------+---------+-----------+------------+
|          ENDPOINT          |        ID        | VERSION | IS LEADER | RAFT TERM  |
+----------------------------+------------------+---------+-----------+------------+
| https://192.168.56.11:2379 | 8e9e05c52164694d |   3.6.5 |     false |          4 |
| https://192.168.56.12:2379 | 2b3c8f1a9d0e7c45 |   3.6.5 |      true |          4 |
| https://192.168.56.13:2379 | 5f7a1c3e8b2d4096 |   3.6.5 |     false |          4 |
+----------------------------+------------------+---------+-----------+------------+

Three members, one leader, all on the same Raft term. The output is trimmed to the useful columns.

Example · Watch a failover

Stop the kubelet and the containers on the scheduler leader's node (in a lab), then read the Lease again:

ssh controlplane2 'sudo systemctl stop kubelet && sudo crictl stop $(sudo crictl ps -q --name kube-scheduler)'
sleep 20
kubectl -n kube-system get lease kube-scheduler -o jsonpath='{.spec.holderIdentity}{"\n"}'
controlplane3_0e4d2a7c-...

Within about 15 seconds another scheduler took the Lease, and new Pods are scheduled as before. Start the kubelet again with sudo systemctl start kubelet on controlplane2.

Tricks

Common mistakes

  • Building a "HA" control plane with 2 nodes. Losing either one loses the etcd majority. Use 3.
  • Pointing workers at one control plane node's IP. Then that node is still a single point of failure, whatever runs behind it. Every kubeconfig must name the control plane endpoint.
  • Forgetting --control-plane-endpoint at kubeadm init. kubeadm cannot convert that cluster to HA later.
  • Expecting three active schedulers. Two of them are standing by; that is correct, not a fault.
  • Making the load balancer the new single point of failure. One HAProxy VM in front of three control planes just moves the problem.

Recap

  • Without a control plane, workloads run on but nothing can change. HA removes that single point of failure.
  • 3 or 5 control plane nodes behind one load balancer address, set as --control-plane-endpoint at kubeadm init.
  • API servers: active-active. Scheduler and controller manager: one leader each, chosen through a Lease.
  • etcd commits a write when a majority agrees: 3 members survive 1 failure, 5 survive 2.
  • Stacked etcd (kubeadm's default) needs 3 machines; external etcd needs 6 but decouples the failures.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Practise: try it on a real cluster

A hands-on lab for this lesson. You get goals, not steps: any solution that reaches them passes.

  • Larkspur's cluster has one control plane node and a load balancer already in front of it. Join two prepared machines as control plane nodes, so that the cluster and its etcd keep working when one of them is down.

    Build · Level 3 · challenge · target 25 min

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.