Lesson 11 · Section 2: Core Concepts
Lesson 11: Kube Controller Manager: the loops that keep the cluster as you declared it
What the kube-controller-manager is, how its control loops turn a Deployment into Pods and react to a dead node, how leader election works, and how to find and fix it when nothing gets created any more. · 22 min read · 5 min video
Official competencies this lesson covers
Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.
Why the controller manager exists
Kubernetes is declarative: you describe the state you want, and the cluster is supposed to get there and stay there. But the API server, the component you talk to, only validates your objects and stores them in etcd. It does not start a container, replace a crashed Pod or notice that a node has lost power.
That work is done by controllers. A controller is a small program that watches one kind of object and keeps nudging the cluster until reality matches what the object asks for. The kube-controller-manager is the control plane component that runs almost all of the built-in controllers, together, in one process.
The idea is borrowed from a thermostat. You set a temperature (the desired state), the thermostat measures the room (the current state) and switches the heating on or off until the two agree. It never "finishes": it keeps measuring. Each controller is a thermostat for one kind of Kubernetes object.
What it is made of
Parts:
- You (kubectl apply)
- API server (the only way in)
- etcd (stored objects)
- Deployment (controller), in kube-controller-manager
- ReplicaSet (controller), in kube-controller-manager
- Node lifecycle (controller), in kube-controller-manager
- EndpointSlice (controller), in kube-controller-manager
- Namespace (controller), in kube-controller-manager
- About 40 more (Job, CronJob, PV...), in kube-controller-manager
Connections:
- You to API server: desired state
- API server and etcd
- API server and ReplicaSet: watch and write
The kube-controller-manager is a single binary and a single process, but inside it run about fifty independent controllers. Each one owns one job. These are the ones worth knowing for the CKA:
| Controller | Watches | What it does |
|---|---|---|
| Deployment | Deployments | Creates and scales ReplicaSets to roll out a new version or roll back |
| ReplicaSet | ReplicaSets, Pods | Creates or deletes Pods until the count matches replicas |
| StatefulSet, DaemonSet, Job, CronJob | Their own kind, Pods | The same idea for the other workload types |
| Node lifecycle | Nodes, Leases | Marks silent nodes NotReady or Unknown and taints them |
| Taint eviction | Nodes, Pods | Deletes Pods that do not tolerate a NoExecute taint |
| EndpointSlice | Services, Pods | Keeps the list of ready Pod addresses behind every Service |
| Namespace | Namespaces | Deletes everything inside a namespace that is being deleted |
| ServiceAccount | Namespaces | Creates the default ServiceAccount in every new namespace |
| Garbage collector | Every object | Deletes objects whose owner is gone (Pods of a deleted ReplicaSet) |
| PersistentVolume binder | PVs, PVCs | Binds a claim to a matching volume |
| CSR signing | CertificateSigningRequests | Signs approved requests with the cluster CA (new kubelets) |
| Horizontal Pod Autoscaler | HPAs, metrics | Changes replicas to follow load |
Three rules hold for every one of them, and they explain most of the component's behaviour:
- A controller only talks to the API server. It never reads etcd, never calls a kubelet and never calls another controller. It reads objects and writes objects.
- A controller owns one concern. The ReplicaSet controller counts Pods; it has no idea what a rollout is. The Deployment controller manages rollouts; it never creates a Pod.
- A controller never stops. It does not run once per command. It reacts to every change, for as long as the process lives.
How it works
The control loop
- Observe the objects
- Compare spec with reality
- Act through the API server
- Repeat
Take the ReplicaSet controller. It observes ReplicaSets and the Pods that match their selectors. For each ReplicaSet
it compares spec.replicas with the number of matching Pods. Too few: it creates Pods from the template. Too many:
it deletes some. Equal: it does nothing. Then it writes what it saw into status, which is the READY column you
read with kubectl get.
The important property is that a controller reacts to the state, not to the event that caused it. It does not matter whether a Pod is missing because you deleted it, because its node burned down or because the controller manager itself was restarting at that moment. The loop sees "wanted 3, found 2" and creates one. This is why Kubernetes heals itself, and why a controller that was down for an hour simply catches up when it comes back.
Controllers form chains
Parts:
- You (create deployment)
- Deployment web (replicas: 3)
- ReplicaSet (web-5d8f, wants 3)
- 3 Pods (Pending, no node yet)
- kubelet (starts containers)
- Deployment (controller), in kube-controller-manager
- ReplicaSet (controller), in kube-controller-manager
- kube-scheduler (picks a node)
Connections:
- You to Deployment web: creates
- Deployment web to Deployment: seen by
- Deployment to ReplicaSet: creates
- ReplicaSet to ReplicaSet: seen by
- ReplicaSet to 3 Pods: creates
- kube-scheduler to 3 Pods: binds
- 3 Pods to kubelet: run by
No controller does a whole job on its own. kubectl create deployment web --image=nginx --replicas=3 sets off a
chain in which each link only reacts to an object written by the link before:
- The API server stores the Deployment. Nothing else has happened yet.
- The Deployment controller sees a Deployment without a ReplicaSet and creates one, named after the Deployment plus a hash of the Pod template.
- The ReplicaSet controller sees a ReplicaSet that wants three Pods and has none, and creates three Pods. They
are
Pendingand have no node. - The kube-scheduler sees Pods without a node and binds each to one.
- The kubelet on that node sees a Pod bound to it and starts the containers.
Because every step is an object in the API, you can watch the chain and find the broken link with kubectl get and
kubectl describe. A Deployment with no ReplicaSet points at the controller manager. Pods that stay Pending with
no node point at the scheduler. Pods with a node that never start point at the kubelet.
Under the hood · How a controller watches without hammering the API server
- A controller does not poll. It opens a watch on the API server, receives every change as it happens, and keeps a local, read-only copy of the objects in memory (an informer cache). Comparing is then a cheap local lookup.
- All controllers in the process share those caches. Fifty controllers that all need Pods cause one watch on Pods, not fifty. This is the main reason they are compiled into one binary instead of fifty.
- A change does not run the logic directly. It puts the object's name on a work queue. Workers take names from the queue and reconcile that one object. If a reconcile fails, the name goes back on the queue with an increasing delay, which is why a controller retries forever without flooding the API server.
- Two controllers never lock each other out. Every write carries the
resourceVersionthe controller last saw. If the object changed in between, the API server answers409 Conflictand the controller reads it again and retries. - Ownership is recorded on the objects: each Pod has an
ownerReferencesentry that names its ReplicaSet. The garbage collector uses those links, so deleting a Deployment removes its ReplicaSets and their Pods. - With
--use-service-account-credentials=true(kubeadm sets it) each controller uses its own ServiceAccount inkube-system, such asreplicaset-controller, with only the permissions it needs. That is the name you see in events and in audit logs.
When a node dies
Parts:
- Node goes silent (no Lease renewals)
- Grace period (50 s, checked every 5)
- Ready: Unknown (taint: unreachable)
- Pods tolerate it (for 300 s by default)
- Pods deleted (taint eviction ctrl)
- New Pods created (ReplicaSet controller)
- Running again (on a healthy node)
Connections:
- Node goes silent to Grace period
- Grace period to Ready: Unknown: node lifecycle
- Ready: Unknown to Pods tolerate it
- Pods tolerate it to Pods deleted: time is up
- Pods deleted to New Pods created
- New Pods created to Running again: scheduler
The node lifecycle controller is the reason workloads survive a dead machine, and its timing is a favourite source of confusion.
- Every kubelet renews a Lease object in the
kube-node-leasenamespace every 10 seconds. That is its heartbeat. - The node lifecycle controller looks at every node every 5 seconds (
--node-monitor-period). When a node has been silent for 50 seconds (--node-monitor-grace-period), it sets the node'sReadycondition toUnknownand adds the taintnode.kubernetes.io/unreachablewith the effectsNoScheduleandNoExecute.kubectl get nodesnow showsNotReady. - Every Pod carries a toleration for that taint with
tolerationSeconds: 300. The API server adds it when the Pod is created, unless the Pod sets its own. - After those 300 seconds the taint eviction controller deletes the Pods. Their ReplicaSet (or StatefulSet, or Job) controller sees Pods missing and creates replacements, and the scheduler puts them on healthy nodes.
So with defaults the gap is about six minutes: 50 seconds to decide, then 5 minutes of patience. It is deliberately slow, because a node that is only cut off for a minute should not have its workloads moved.
Two details that follow from the same design:
- DaemonSet Pods are never evicted this way. They tolerate both taints without a time limit, because a replacement could only run on the same dead node anyway.
- A mass outage stops evictions. If more than 55% of the nodes in a zone look unhealthy at once, the controller assumes the control plane is the one that is cut off, and slows down or stops evicting rather than deleting everything.
High availability: leader election
Parts:
- API server (objects to reconcile)
- Lease (kube-system)
- cp-1: leader (runs every loop)
- cp-2: standby (waits, does nothing)
- cp-3: standby (waits, does nothing)
Connections:
- cp-1: leader to Lease: holds, renews
- cp-1: leader to API server: reconciles
- cp-2: standby to Lease: watches
- cp-3: standby to Lease: watches
A highly available control plane runs one kube-controller-manager per control plane node. Two ReplicaSet controllers acting on the same ReplicaSet would both create the missing Pod, so only one instance may be active.
They settle it with a Lease named kube-controller-manager in kube-system. With --leader-elect=true (the
default) every instance tries to take the Lease. The winner writes its name into holderIdentity, starts its
controllers and keeps renewing the Lease every couple of seconds. The others do nothing but watch. If the leader
has not renewed for 15 seconds (--leader-elect-lease-duration), a standby takes the Lease and starts its own
controllers from the current state of the cluster. Nothing is lost, because all state lives in the API server and
none in the process.
The kube-scheduler uses the same mechanism with its own Lease. The API server does not need it: every API server instance is active at the same time.
Where it runs and how it is configured
On a cluster built with kubeadm, which is what the exam uses, the controller manager is a static Pod. The kubelet on the control plane node starts it straight from a file, without asking the API server:
| What | Where |
|---|---|
| Manifest | /etc/kubernetes/manifests/kube-controller-manager.yaml |
| Pod | kube-controller-manager-<node name> in kube-system |
| Identity and API server address | /etc/kubernetes/controller-manager.conf (user system:kube-controller-manager) |
| Certificates and keys it uses | /etc/kubernetes/pki/ (ca.crt, ca.key, sa.key) |
| Health endpoint | https://127.0.0.1:10257/healthz |
On a cluster installed "the hard way" it is a systemd service instead: look for
/etc/systemd/system/kube-controller-manager.service and use systemctl status and journalctl -u.
Configuration is nothing but command-line flags in that manifest. The ones you should recognise:
| Flag | Meaning | Default or kubeadm value |
|---|---|---|
--kubeconfig | How to reach the API server and who to be | /etc/kubernetes/controller-manager.conf |
--controllers | Which controllers run: * is all default ones, name adds one, -name switches one off | *,bootstrapsigner,tokencleaner |
--leader-elect | Take part in leader election | true |
--node-monitor-period | How often node health is checked | 5s |
--node-monitor-grace-period | Silence allowed before a node is marked unhealthy | 50s |
--cluster-signing-cert-file, --cluster-signing-key-file | The CA that signs certificate requests | ca.crt, ca.key |
--service-account-private-key-file | Key that signs ServiceAccount tokens | sa.key |
--root-ca-file | CA published to every namespace as kube-root-ca.crt | ca.crt |
--cluster-cidr, --allocate-node-cidrs | Pod network range, and whether each node gets a slice of it | set from --pod-network-cidr |
--bind-address | Address the health and metrics port listens on | 127.0.0.1 |
To change a flag, edit the manifest and save. The kubelet notices the changed file, stops the old Pod and starts a
new one. There is nothing to kubectl apply and nothing to restart by hand.
What breaks when it is down
Knowing the symptoms is what lets you name the faulty component in seconds. With the controller manager stopped:
- Pods that are already running keep running, and Services keep working. The data path does not depend on it.
kubectl create deploymentandkubectl scalesucceed, but no ReplicaSet and no Pod appears. The Deployment stays at0/3andkubectl describeshows no events at all.- A Pod you delete is not replaced.
- A node that dies stays
Readyinkubectl get nodes, and nothing is moved off it. - New Pods do not get into Service endpoints, and a rolling update never progresses.
- A new namespace gets no
defaultServiceAccount, so creating a Pod in it fails withserviceaccount "default" not found. A deleted namespace hangs inTerminating. - Jobs create no Pods, CronJobs never fire, and PersistentVolumeClaims stay
Pending.
Compare this with a broken scheduler: there the Pods are created, and stay Pending with no node.
Using it
Example · Find the controller manager and read its settings
You are on the control plane node of a kubeadm cluster and want to know how the controller manager is configured.
kubectl -n kube-system get pods -l component=kube-controller-manager -o wide
sudo grep -- '--' /etc/kubernetes/manifests/kube-controller-manager.yaml # every flag, one per line
kubectl -n kube-system get lease kube-controller-manager # who is the leader
NAME HOLDER AGE
kube-controller-manager controlplane_3f1c9b9e-6a2f-4d0c-9c57-0d4b8c1c2f11 12d
The part of HOLDER before the underscore is the node whose instance is active. A flag that is not in the manifest
has its default value; look defaults up on the kube-controller-manager reference page, not from memory.
Example · Watch the controllers work
Events record which controller did what, so you can see the chain from the previous section with your own eyes.
kubectl create deployment web --image=nginx:1.29 --replicas=3
kubectl get events --sort-by=.lastTimestamp | grep -E 'deployment-controller|replicaset-controller'
2s Normal ScalingReplicaSet deployment/web Scaled up replica set web-5d8f7c9b4 from 0 to 3
2s Normal SuccessfulCreate replicaset/web-5d8f7c9b4 Created pod: web-5d8f7c9b4-7xk2p
Now delete one Pod and watch the ReplicaSet controller replace it within a second:
kubectl delete pod web-5d8f7c9b4-7xk2p --wait=false
kubectl get pods -l app=web --watch
Example · Repair a controller manager that will not start
A Deployment was scaled to 3 a few minutes ago and still shows 0/3. kubectl describe deployment web shows no
events. Work from the symptom to the file:
kubectl -n kube-system get pods # kube-controller-manager-controlplane: CrashLoopBackOff
kubectl -n kube-system logs kube-controller-manager-controlplane --tail=20
kubectl -n kube-system describe pod kube-controller-manager-controlplane # image, command, mounts, events
The log or the events name the cause. The usual ones, all inside the manifest:
| What you see | Cause |
|---|---|
executable file not found in $PATH | A typo in the binary name under command |
unknown flag: --... | A misspelled or removed flag |
stat /etc/kubernetes/...: no such file or directory | A wrong path in a flag, or a hostPath volume that points somewhere else |
ErrImagePull or ImagePullBackOff | A wrong image name or tag |
The Pod is missing from kubectl get pods entirely | The YAML is invalid, so the kubelet cannot create it at all |
Fix the file and let the kubelet do the rest:
sudo cp /etc/kubernetes/manifests/kube-controller-manager.yaml /root/kcm.yaml.bak # outside the manifests directory
sudo vim /etc/kubernetes/manifests/kube-controller-manager.yaml
watch kubectl -n kube-system get pods # Running 1/1 after about half a minute
kubectl get deployment web # 3/3, with nothing else to do
If the Pod never shows up in kubectl, ask the node directly:
sudo crictl ps -a | grep kube-controller-manager # the container, even when it has exited
sudo crictl logs <container id>
sudo journalctl -u kubelet --since "5 min ago" | grep -i controller-manager # YAML and mount errors
Example · Make one workload fail over faster
A stateless API should move off a dead node after 30 seconds instead of 5 minutes. Do not touch the controller manager: override the tolerations in the Pod template.
spec:
template:
spec:
tolerations:
- key: node.kubernetes.io/unreachable
operator: Exists
effect: NoExecute
tolerationSeconds: 30
- key: node.kubernetes.io/not-ready
operator: Exists
effect: NoExecute
tolerationSeconds: 30
The node still needs 50 seconds to be declared unreachable, so the Pods are replaced after about 80 seconds.
Tricks
Common mistakes
- Editing the Pod instead of the manifest.
kubectl edit pod kube-controller-manager-...changes a read-only mirror of the static Pod and has no effect. The file on the control plane node is the only source. - Looking on the wrong node. The manifest is on the control plane node. In the exam,
sshto it first, and usesudo. - Expecting instant failover. A dead node is not noticed for 50 seconds and its Pods are not replaced for about
six minutes. Pods that stay
Runningon aNotReadynode during that time are normal, not a bug. - Blaming the controller manager for Pending Pods. If the Pods exist, the controllers did their job.
Pendingis a scheduling or resource question. - Breaking the YAML while fixing a flag. One wrong indent and the Pod disappears from
kubectlentirely. Checkjournalctl -u kubeletand compare with your backup. - Forgetting the standbys. With three control plane nodes, the logs of two instances only say that they are
waiting for the Lease. Read the logs of the one named in the Lease's
HOLDER.
Recap
- The kube-controller-manager is one process running dozens of control loops; each watches the API server and writes back to it, and talks to nothing else.
- Every loop does the same thing forever: observe, compare spec with reality, act. Reacting to state, not to events, is what makes the cluster self-healing.
- Controllers form chains through objects: Deployment → ReplicaSet → Pods, then the scheduler and the kubelet.
- A dead node is marked after 50 seconds and its Pods are replaced after the 300 second toleration; only the Lease holder among several instances is active.
- On kubeadm it is a static Pod: diagnose with
kubectl -n kube-system logsorcrictl logs, fix/etc/kubernetes/manifests/kube-controller-manager.yaml, and the kubelet restarts it.
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.
A Deployment was scaled and no pod appears; nothing is Pending either. Work out which component is not doing its job and repair it on the control plane node.
Fix · Level 2 · standard · target 15 min
Discussion
Learners ask and answer questions here. Sign in to read and join the discussion.