Lesson 13 · Section 2: Core Concepts
Lesson 13: Kubelet: the agent that turns Pod specs into running containers
What the kubelet does on every node, how it starts Pods through the container runtime, how it reports node health, where its configuration lives, and how to fix a node that went NotReady. · 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 kubelet exists
The control plane is a set of programs that store and decide. The API server stores a Pod object, and the scheduler writes a node name into it. At that point nothing is running anywhere: a Pod is still only a record in etcd.
Somebody has to do the real work on the machine: pull the image, create the containers, mount the volumes, restart what crashes, and tell the cluster how the node is doing. That somebody is the kubelet, an agent that runs on every node, control plane nodes included.
Two facts follow from this, and both matter in the exam:
- The kubelet is not a Pod. It has to exist before any Pod can, so it runs as a normal Linux service under
systemd.
kubectl get pods -Anever shows it, andkubectl logscannot read its logs. - kubeadm does not install it. You install the
kubeletpackage yourself on every node (together withkubeadmandkubectl); kubeadm only writes its configuration and starts it.
What the kubelet is made of
Parts:
- API server (Pods bound to node)
- Manifest folder (/etc/kubernetes/manifests), in One node
- kubelet (systemd service), in One node
- CSI driver (mounts volumes), in One node
- CNI plugin (Pod IP and routes), in One node
- containerd (CRI socket), in One node
- Pod containers (sandbox + containers), in One node
Connections:
- API server and kubelet: watch / status
- Manifest folder to kubelet: static Pods
- kubelet to containerd: CRI (gRPC)
- containerd to CNI plugin: network
- containerd to Pod containers: starts
- kubelet to CSI driver: mount
The kubelet sits between the API server and everything local to the node:
| Neighbour | Interface | What the kubelet uses it for |
|---|---|---|
| API server | HTTPS, with a client certificate | Watch Pods bound to this node, fetch their ConfigMaps and Secrets, write Pod and Node status |
| Container runtime (containerd, CRI-O) | CRI, gRPC over a Unix socket | Pull images, create the Pod sandbox, start and stop containers, read logs, exec |
| Network plugin | CNI, called by the runtime | Give each Pod sandbox an IP address and routes |
| Storage drivers | CSI, gRPC over a Unix socket | Mount and unmount volumes into Pods |
| Manifest folder | Files on disk | Run static Pods without any API server |
The kubelet also listens. Its HTTPS server on port 10250 is what the API server connects to when you run
kubectl logs, kubectl exec or kubectl port-forward, and where the metrics server collects CPU and memory
figures (the kubelet embeds cAdvisor for those). A plain health endpoint answers on 127.0.0.1:10248/healthz.
How it works
The sync loop
Parts:
- API server (Pods for this node)
- Manifest folder (static Pods)
- Sync loop (desired vs actual)
- Probes (liveness, readiness)
- Container runtime (sandbox, containers)
- PLEG (container events)
Connections:
- API server and Sync loop: watch / status
- Manifest folder to Sync loop: reads
- Sync loop to Container runtime: create, kill
- Container runtime to PLEG: relist
- PLEG to Sync loop: changed
- Probes to Container runtime: check
- Probes to Sync loop: results
The kubelet is a control loop, like the controllers in the control plane, but for one node. It gathers the Pods it should run from its sources (the API server, the manifest folder, and optionally a URL), compares each with what the runtime reports, and acts on the difference. It repeats this whenever something changes, and at least about once a minute for every Pod even when nothing seems to have changed.
For a new Pod the order of work is always the same, and it explains the states you see in kubectl get pods:
- Admit: does it fit this node?
- Create cgroups, mount volumes
- Runtime creates sandbox, CNI gives the IP
- Pull images
- Init containers, one by one
- App containers, then probes
- A Pod stuck in
ContainerCreatingis waiting in step two or three: a missing ConfigMap or Secret, a volume that will not mount, or a CNI problem.kubectl describe podnames which. ImagePullBackOffis step four,Init:0/1is step five, andCrashLoopBackOffis step six failing again and again.
Under the hood · PLEG, probes and restarts
- PLEG (Pod Lifecycle Event Generator) asks the runtime for the full list of containers about once a second and
turns differences into events ("container died") that wake the sync loop. If a relist takes more than three
minutes, the node goes
NotReadywith the messagePLEG is not healthy, which nearly always means the runtime is hanging or the node is badly overloaded. - Probes are run by the kubelet, from the node, not by the control plane. A failed liveness probe makes the kubelet kill and restart the container. A failed readiness probe only changes the Pod's Ready condition; the control plane then takes the Pod out of Service endpoints.
- Restarts are local. The kubelet restarts containers according to
restartPolicy, waiting 10s, 20s, 40s and so on up to five minutes between attempts. That waiting is whatCrashLoopBackOffmeans. The kubelet never moves a Pod to another node; only a controller (a Deployment, for example) creates a replacement elsewhere. - Containers outlive the kubelet. Stopping or restarting the kubelet does not stop the containers, because the runtime owns them. This is why you can restart the kubelet on a live node without an outage.
- Resources. The kubelet turns requests and limits into cgroup settings, and it protects the node: when memory
or disk runs low it sets
MemoryPressureorDiskPressureand evicts Pods. The default hard thresholds arememory.available<100Mi,nodefs.available<10%andimagefs.available<15%.
Heartbeats and node status
Parts:
- kubelet (on node01)
- Lease node01 (kube-node-lease)
- Node controller (controller manager)
- Node node01 (Ready condition)
- Taint, then evict (unreachable:NoExecute)
Connections:
- kubelet to Lease node01: renew, 10s
- kubelet to Node node01: status
- Node controller to Lease node01: watches
- Node controller to Node node01: Ready: Unknown
- Node controller to Taint, then evict: adds taint
The kubelet registers its own Node object when it first starts, then proves it is alive in two ways:
- It renews a Lease named after the node in the
kube-node-leasenamespace every 10 seconds. This is the real heartbeat: a tiny object, cheap to update. - It writes the Node's
.status(conditions, capacity, allocatable, addresses, kubelet version) when something changes, and at least every five minutes.
The node controller inside kube-controller-manager watches the Leases. If a node misses renewals for the grace period
(under a minute by default), the controller sets the node's Ready condition to Unknown, kubectl get nodes shows
NotReady, and kubectl describe node says "Kubelet stopped posting node status". The node then gets the taint
node.kubernetes.io/unreachable:NoExecute. Pods tolerate that taint for 300 seconds by default, so a Deployment's
Pods are replaced on other nodes roughly five to six minutes after a kubelet dies, not immediately.
How the kubelet proves who it is
The kubelet logs in to the API server with a client certificate whose identity is system:node:<nodeName> in the
group system:nodes. The kubeconfig at /etc/kubernetes/kubelet.conf points to that certificate under
/var/lib/kubelet/pki/, and the kubelet rotates it by itself before it expires. The Node authorizer and the
NodeRestriction admission plugin then keep each kubelet in its lane: it may read only the Secrets and ConfigMaps of
Pods bound to its own node, and may change only its own Node object. A stolen kubelet credential therefore exposes
one node's secrets, not the whole cluster's.
Two kinds of Pods: from the API and static
| Pods from the API server | Static Pods | |
|---|---|---|
| Defined in | The API (created by you or a controller) | A file in the kubelet's staticPodPath |
| Needs a control plane | Yes | No, only the kubelet and the runtime |
| Placed by | The scheduler | Nobody: always on the node that holds the file |
| Visible in kubectl | Yes | Yes, as a read-only mirror Pod named <name>-<nodeName> |
| Change or remove | kubectl edit, kubectl delete | Edit, move or delete the file |
Static Pods solve a chicken-and-egg problem: the API server, etcd, the scheduler and the controller manager cannot be
started by a control plane that does not exist yet. On a kubeadm cluster they are static Pods in
/etc/kubernetes/manifests, started by the kubelet of each control plane node. That is why their names end in the
node name, as in kube-apiserver-controlplane.
Where the configuration lives
Parts:
- systemd (kubelet.service)
- 10-kubeadm.conf (drop-in: builds flags)
- config.yaml (/var/lib/kubelet)
- kubeadm-flags.env (/var/lib/kubelet)
- kubelet.conf (/etc/kubernetes)
- kubelet (/usr/bin/kubelet)
Connections:
- systemd to 10-kubeadm.conf
- 10-kubeadm.conf to config.yaml: --config
- 10-kubeadm.conf to kubeadm-flags.env: extra flags
- 10-kubeadm.conf to kubelet.conf: --kubeconfig
- config.yaml to kubelet
- kubeadm-flags.env to kubelet
- kubelet.conf to kubelet
On a kubeadm node the kubelet's settings come from a short chain of files. You should be able to walk it from memory:
| File | What it holds |
|---|---|
/usr/lib/systemd/system/kubelet.service | The base systemd unit |
.../kubelet.service.d/10-kubeadm.conf | The drop-in that builds the real command line (the binary path and the flags below) |
/var/lib/kubelet/config.yaml | The KubeletConfiguration: almost every setting, including staticPodPath, clusterDNS, cgroupDriver, the client CA file and eviction thresholds |
/var/lib/kubelet/kubeadm-flags.env | A few flags that differ per node, written by kubeadm init and kubeadm join |
/etc/kubernetes/kubelet.conf | The kubeconfig: which API server to call and which client certificate to use |
/var/lib/kubelet/pki/ | The kubelet's client and serving certificates |
The drop-in sits under /usr/lib/systemd/system/ with current packages and under /etc/systemd/system/ with older
ones. You do not need to remember which: systemctl cat kubelet prints the unit and every drop-in with their paths.
A trimmed config.yaml from a kubeadm node:
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
authentication:
x509:
clientCAFile: /etc/kubernetes/pki/ca.crt
cgroupDriver: systemd
clusterDNS:
- 10.96.0.10
clusterDomain: cluster.local
staticPodPath: /etc/kubernetes/manifests
Under the hood · Why these particular settings break clusters
cgroupDrivermust match the container runtime's driver. On systemd machines both should besystemd(kubeadm's default). A mismatch gives an unstable node or a kubelet that refuses to start.clusterDNSis written into every Pod's/etc/resolv.conf. If it does not match the ClusterIP of thekube-dnsService, Pods start fine but cannot resolve any name.clientCAFileis the CA the kubelet trusts for callers of port 10250. A wrong path stops the kubelet at startup with a clear "unable to load client CA file" error.- Swap. By default (
failSwapOn: true) the kubelet refuses to start on a node with swap enabled. This is the classic reason a freshly prepared node fails to join. - Cluster-wide copy. kubeadm keeps the shared configuration in the ConfigMap
kubelet-configinkube-system.kubeadm joinandkubeadm upgrade nodewrite it to/var/lib/kubelet/config.yaml, so a manual edit of that file lasts only until the next upgrade unless you change the ConfigMap too.
Using it
Example · Bring a NotReady node back
node01 shows NotReady. Work from the outside in: the cluster's view, then the service, then its log.
kubectl get nodes
kubectl describe node node01 | grep -A8 Conditions # "Kubelet stopped posting node status"
ssh node01
sudo systemctl status kubelet # inactive? failing and restarting? running?
sudo journalctl -u kubelet --no-pager | tail -n 30
What the state tells you:
inactive (dead): someone stopped it.sudo systemctl enable --now kubeletstarts it and keeps it enabled after a reboot.activating (auto-restart): it crashes at startup. The journal names the cause: a wrong path to the binary or toconfig.yamlin the drop-in, a bad value inconfig.yaml, or a missing certificate file.active (running)but the node is still NotReady: the kubelet runs but cannot do its job. Look in the journal for a refused connection to the API server (wrong server address or port in/etc/kubernetes/kubelet.conf), a runtime that is down (sudo systemctl status containerd), or a missing CNI plugin.
After the fix:
sudo systemctl daemon-reload # only needed if a unit or drop-in file changed
sudo systemctl restart kubelet
exit
kubectl get nodes -w # Ready within about a minute
Example · Run a static Pod on one node
Create a static Pod named web on node01. Find the folder first instead of assuming it, then let kubectl write
the manifest.
ssh node01
sudo grep staticPodPath /var/lib/kubelet/config.yaml # staticPodPath: /etc/kubernetes/manifests
kubectl run web --image=nginx:1.29 --dry-run=client -o yaml \
| sudo tee /etc/kubernetes/manifests/web.yaml
exit
kubectl get pods -o wide # web-node01 is Running on node01
kubectl run --dry-run=client only prints YAML, so it works on a node whose kubectl has no access to the cluster. To
remove the Pod, delete /etc/kubernetes/manifests/web.yaml on node01.
Example · Change a kubelet setting on one node
Raise the Pod limit on node01 from the default 110 to 150.
ssh node01
sudo vi /var/lib/kubelet/config.yaml # add or change: maxPods: 150
sudo systemctl restart kubelet
exit
kubectl get node node01 -o jsonpath='{.status.capacity.pods}' # 150
The file is read only at startup, so nothing changes until the restart. Running Pods are not disturbed by it.
Tricks
Common mistakes
- Looking for a kubelet Pod. There is none. Its state is in
systemctl status kubeletand its logs are injournalctl -u kubelet, on the node itself. - Forgetting
daemon-reload. After editing a unit or drop-in file, systemd keeps using the old version untilsystemctl daemon-reload. Edits toconfig.yamlneed only a restart. - Starting without enabling.
systemctl start kubeletfixes the node until the next reboot. Usesystemctl enable --now kubelet. - Fixing the wrong node.
kubectlruns from where you are, butsystemctland the files act on the machine you are logged in to. Check the prompt before you edit anything, andexitwhen you are done. - Blaming the kubelet for a runtime problem. If the journal is full of errors about
containerd.sock, the runtime is down or its socket path is wrong; restarting the kubelet will not help. - Upgrading in the wrong order. A kubelet must never be newer than the API server. Upgrade the control plane
first, then drain each node, upgrade its kubelet package, run
daemon-reloadand restart it, and uncordon.
Recap
- The kubelet is the node agent: it turns Pod specs into running containers through the CRI runtime, and it is a systemd service, not a Pod.
- It runs a sync loop over Pods from the API server and from the static Pod folder, runs probes, and restarts containers locally.
- Its Lease heartbeat every 10 seconds decides
ReadyorNotReady; Pods on a dead node are replaced after about five minutes. - Settings:
/var/lib/kubelet/config.yaml, flags from the systemd drop-in, identity in/etc/kubernetes/kubelet.conf. - Broken node:
systemctl status kubelet,journalctl -u kubelet, fix the named file,daemon-reloadif needed, restart.
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
2 hands-on labs for this lesson. You get goals, not steps: any solution that reaches them passes.
A worker node is NotReady. Its kubelet is stopped, will not start, and would not come back after a reboot: find all three with systemctl and journalctl.
Fix · Level 2 · standard · target 15 min
A worker was reset by mistake and is no longer a node. Join it again with kubeadm, and give the new Node object what the old one had so that the waiting workload runs on it.
Fix · Level 3 · challenge · target 20 min
Discussion
Learners ask and answer questions here. Sign in to read and join the discussion.