Skip to content
LF Cert Trainer

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

1/11Kube Controller Manager
0:00 / 4:59

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

One process, many control loopskube-controller-managerdesired statewatch and writeYoukubectl applyAPI serverthe only way inetcdstored objectsDeploymentcontrollerReplicaSetcontrollerNode lifecyclecontrollerEndpointSlicecontrollerNamespacecontrollerAbout 40 moreJob, CronJob, PV...
One process, many control loops. Every controller is a loop inside the same process. Each one watches the API server and writes back to it. None of them talks to etcd, to a kubelet or to another controller directly.

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:

ControllerWatchesWhat it does
DeploymentDeploymentsCreates and scales ReplicaSets to roll out a new version or roll back
ReplicaSetReplicaSets, PodsCreates or deletes Pods until the count matches replicas
StatefulSet, DaemonSet, Job, CronJobTheir own kind, PodsThe same idea for the other workload types
Node lifecycleNodes, LeasesMarks silent nodes NotReady or Unknown and taints them
Taint evictionNodes, PodsDeletes Pods that do not tolerate a NoExecute taint
EndpointSliceServices, PodsKeeps the list of ready Pod addresses behind every Service
NamespaceNamespacesDeletes everything inside a namespace that is being deleted
ServiceAccountNamespacesCreates the default ServiceAccount in every new namespace
Garbage collectorEvery objectDeletes objects whose owner is gone (Pods of a deleted ReplicaSet)
PersistentVolume binderPVs, PVCsBinds a claim to a matching volume
CSR signingCertificateSigningRequestsSigns approved requests with the cluster CA (new kubelets)
Horizontal Pod AutoscalerHPAs, metricsChanges 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

  1. Observe the objects
  2. Compare spec with reality
  3. Act through the API server
  4. Repeat
Every controller, all the time

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

From one Deployment to running Podskube-controller-managercreatesseen bycreatesseen bycreatesbindsrun byYoucreate deploymentDeployment webreplicas: 3ReplicaSetweb-5d8f, wants 33 PodsPending, no node yetkubeletstarts containersDeploymentcontrollerReplicaSetcontrollerkube-schedulerpicks a node
From one Deployment to running Pods. Controllers never call each other. Each one reacts to an object that the one before it wrote to the API server, which is why you can follow the whole chain with kubectl get.

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:

  1. The API server stores the Deployment. Nothing else has happened yet.
  2. The Deployment controller sees a Deployment without a ReplicaSet and creates one, named after the Deployment plus a hash of the Pod template.
  3. The ReplicaSet controller sees a ReplicaSet that wants three Pods and has none, and creates three Pods. They are Pending and have no node.
  4. The kube-scheduler sees Pods without a node and binds each to one.
  5. 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 resourceVersion the controller last saw. If the object changed in between, the API server answers 409 Conflict and the controller reads it again and retries.
  • Ownership is recorded on the objects: each Pod has an ownerReferences entry 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 in kube-system, such as replicaset-controller, with only the permissions it needs. That is the name you see in events and in audit logs.

When a node dies

What happens when a node stops answeringnode lifecycletime is upschedulerNode goes silentno Lease renewalsGrace period50 s, checked every 5Ready: Unknowntaint: unreachablePods tolerate itfor 300 s by defaultPods deletedtaint eviction ctrlNew Pods createdReplicaSet controllerRunning againon a healthy node
What happens when a node stops answering. With the defaults, Pods on a dead node are replaced after roughly six minutes: 50 seconds to decide the node is gone, then the 300 seconds that every Pod tolerates the unreachable taint.

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.

  1. Every kubelet renews a Lease object in the kube-node-lease namespace every 10 seconds. That is its heartbeat.
  2. 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's Ready condition to Unknown and adds the taint node.kubernetes.io/unreachable with the effects NoSchedule and NoExecute. kubectl get nodes now shows NotReady.
  3. 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.
  4. 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

Three copies, one leaderholds, renewsreconcileswatcheswatchesAPI serverobjects to reconcileLeasekube-systemcp-1: leaderruns every loopcp-2: standbywaits, does nothingcp-3: standbywaits, does nothing
Three copies, one leader. Every control plane node runs a controller manager, but only the holder of the Lease runs the loops. If it stops renewing, a standby takes the Lease and starts working.

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:

WhatWhere
Manifest/etc/kubernetes/manifests/kube-controller-manager.yaml
Podkube-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 endpointhttps://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:

FlagMeaningDefault or kubeadm value
--kubeconfigHow to reach the API server and who to be/etc/kubernetes/controller-manager.conf
--controllersWhich controllers run: * is all default ones, name adds one, -name switches one off*,bootstrapsigner,tokencleaner
--leader-electTake part in leader electiontrue
--node-monitor-periodHow often node health is checked5s
--node-monitor-grace-periodSilence allowed before a node is marked unhealthy50s
--cluster-signing-cert-file, --cluster-signing-key-fileThe CA that signs certificate requestsca.crt, ca.key
--service-account-private-key-fileKey that signs ServiceAccount tokenssa.key
--root-ca-fileCA published to every namespace as kube-root-ca.crtca.crt
--cluster-cidr, --allocate-node-cidrsPod network range, and whether each node gets a slice of itset from --pod-network-cidr
--bind-addressAddress the health and metrics port listens on127.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 deployment and kubectl scale succeed, but no ReplicaSet and no Pod appears. The Deployment stays at 0/3 and kubectl describe shows no events at all.
  • A Pod you delete is not replaced.
  • A node that dies stays Ready in kubectl 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 default ServiceAccount, so creating a Pod in it fails with serviceaccount "default" not found. A deleted namespace hangs in Terminating.
  • 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 seeCause
executable file not found in $PATHA typo in the binary name under command
unknown flag: --...A misspelled or removed flag
stat /etc/kubernetes/...: no such file or directoryA wrong path in a flag, or a hostPath volume that points somewhere else
ErrImagePull or ImagePullBackOffA wrong image name or tag
The Pod is missing from kubectl get pods entirelyThe 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, ssh to it first, and use sudo.
  • 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 Running on a NotReady node during that time are normal, not a bug.
  • Blaming the controller manager for Pending Pods. If the Pods exist, the controllers did their job. Pending is a scheduling or resource question.
  • Breaking the YAML while fixing a flag. One wrong indent and the Pod disappears from kubectl entirely. Check journalctl -u kubelet and 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 logs or crictl 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.