Inside a Kubernetes cluster

ExplainedKubernetesDevOps, Hands OnBy Cloud Hands On

The control plane, etcd, controllers and leader election, in plain English: what happens between kubectl apply and a running pod.

When you run kubectl apply, the API server checks who you are and whether you're allowed, validates the object and saves it in etcd. Nothing has run yet. Controllers notice the new object and act: the Deployment controller creates a ReplicaSet, which creates pods. The scheduler sees pods with no node and picks one. The kubelet on that node sees a pod assigned to it and asks the container runtime to start it.

Everything talks only to the API server, and every part is a loop that watches and reconciles: compare what's wanted with what exists, then close the gap. That's why Kubernetes heals itself, and why one broken controller or a slow etcd can make the whole cluster seem stuck.

etcd keeps its copies consistent with the Raft algorithm: a majority (quorum) must agree on every write. With 3 members it survives 1 failure; with 5, it survives 2. An even number adds no safety. The scheduler and controller manager run several copies for safety, but only one is active: they take turns through leader election, using Lease objects that the leader must keep renewing.

Cost. Free to learn; practise on a kind cluster on your own computer.

Use it when

How it works

API server
The front door: authentication, authorisation, admission and storage in etcd.
etcd
The cluster's database, kept consistent by quorum.
Scheduler
Chooses a node for each unscheduled pod, using requests, affinity, taints and spread.
Controller manager
Runs the built-in controllers (deployments, ReplicaSets, nodes, jobs and more).
kubelet and runtime
Start and watch containers on each node, and report back.

Options

Managed control plane (AKS)
Microsoft runs the API server and etcd; you manage nodes and workloads.
Self-managed (kubeadm)
You run and back up etcd and the control plane yourself.

Example. Fernhill Cloud's self-managed lab cluster ran etcd on 2 members to 'add safety'. When one failed, writes stopped: 1 of 2 isn't a majority. They moved to 3 members, which survives a failure.

Don't confuse it with

Imperative scripts
Do steps once. Kubernetes controllers keep checking and correcting forever.
A database cluster
etcd is one, with the same quorum rules.

Words to know

Reconciliation loop
Watch, compare, act: the pattern every controller follows.
Quorum
The majority of etcd members needed to agree on a write.
Lease
An object the active leader keeps renewing; if it stops, another copy takes over.
Admission controller
A check in the API server that can reject or change objects before they're saved.

Where to look

  1. Terminal
  2. kubectl get pods -n kube-system
  3. kubectl get lease -n kube-system

Practise it

Read it in the guide, next to the tasks and labs.

Open in DevOps, Hands On

Keep going