CodeBlanks Logo Icon CodeBlanks

controller-manager

Learn the controllers of kube-controller-manager.

controller-manager

kube-controller-manager runs dozens of controllers in a single process: the Deployment, ReplicaSet, StatefulSet, Job, Node, EndpointSlice, ServiceAccount and Namespace controllers... Each watches its own resource type and moves the actual state toward the desired state. For example:

  • The Deployment controller creates ReplicaSets and adjusts their replicas.
  • The ReplicaSet controller creates and deletes pods.
  • The Node controller marks unresponsive nodes and has their pods evicted.
$ kubectl get pods -n kube-system -l component=kube-controller-manager
NAME                                    READY   STATUS
kube-controller-manager-control-plane   1/1     Running

Leader election

In highly available clusters, a controller-manager runs on each control-plane node, but only one is the leader at a time; the others wait. Leadership is held with a Lease object in kube-system and renewed regularly:

$ kubectl get lease -n kube-system kube-controller-manager -o jsonpath='{.spec.holderIdentity}'
cp-2_4f9a1c3e-…
$ kubectl get lease -n kube-system

The same mechanism is used for kube-scheduler and for operators you write yourself.

Practice Find the leader

Write two commands: list the Lease objects in kube-system; print the holderIdentity value of the kube-controller-manager Lease with jsonpath='{.spec.holderIdentity}'.

Starter code

terminal
# buraya yaz

Sample solution

terminal
kubectl get lease -n kube-system
kubectl get lease kube-controller-manager -n kube-system -o jsonpath='{.spec.holderIdentity}'

Expected output

NAME                      HOLDER                    AGE
kube-controller-manager   cp-2_4f9a1c3e-…           12d
kube-scheduler            cp-1_9b2d7e4a-…           12d
cp-2_4f9a1c3e-…

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What happens if a node hasn't responded for 5 minutes?

  • The pods wait forever
  • The node is deleted
  • The node is marked NotReady and its pods are evicted and recreated on other nodes Correct answer
  • The cluster stops

Explanation: The eviction delay is set with taints and tolerationSeconds.

2 List the leadership objects.

Question
kubectl get ____ -n kube-system
Answer
kubectl get lease -n kube-system

Explanation: Lease objects are in the coordination.k8s.io group.

3 Match.

Term Meaning
Deployment denetleyicisi Manages ReplicaSets
ReplicaSet denetleyicisi Manages pods
Node denetleyicisi Unresponsive nodes
Lease Leader record

All lessons in Expert