Skip to content
LF Cert Trainer

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

1/10Kubelet
0:00 / 4:40

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 -A never shows it, and kubectl logs cannot read its logs.
  • kubeadm does not install it. You install the kubelet package yourself on every node (together with kubeadm and kubectl); kubeadm only writes its configuration and starts it.

What the kubelet is made of

The kubelet and its neighbours on a nodeOne nodewatch / statusstatic PodsCRI (gRPC)networkstartsmountAPI serverPods bound to nodeManifest folder/etc/kubernetes/manifestskubeletsystemd serviceCSI drivermounts volumesCNI pluginPod IP and routescontainerdCRI socketPod containerssandbox + containers
The kubelet and its neighbours on a node. The kubelet is the only component that talks to both the API server and the container runtime. The runtime, not the kubelet, calls the CNI plugin to give each Pod its network.

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:

NeighbourInterfaceWhat the kubelet uses it for
API serverHTTPS, with a client certificateWatch 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 socketPull images, create the Pod sandbox, start and stop containers, read logs, exec
Network pluginCNI, called by the runtimeGive each Pod sandbox an IP address and routes
Storage driversCSI, gRPC over a Unix socketMount and unmount volumes into Pods
Manifest folderFiles on diskRun 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

The sync loop: desired state against actual statewatch / statusreadscreate, killrelistchangedcheckresultsAPI serverPods for this nodeManifest folderstatic PodsSync loopdesired vs actualProbesliveness, readinessContainer runtimesandbox, containersPLEGcontainer events
The sync loop: desired state against actual state. The kubelet never runs a script once. It keeps comparing the Pods it should run with the containers that really run, and fixes any difference.

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:

  1. Admit: does it fit this node?
  2. Create cgroups, mount volumes
  3. Runtime creates sandbox, CNI gives the IP
  4. Pull images
  5. Init containers, one by one
  6. App containers, then probes
Starting one Pod
  • A Pod stuck in ContainerCreating is waiting in step two or three: a missing ConfigMap or Secret, a volume that will not mount, or a CNI problem. kubectl describe pod names which.
  • ImagePullBackOff is step four, Init:0/1 is step five, and CrashLoopBackOff is 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 NotReady with the message PLEG 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 what CrashLoopBackOff means. 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 MemoryPressure or DiskPressure and evicts Pods. The default hard thresholds are memory.available<100Mi, nodefs.available<10% and imagefs.available<15%.

Heartbeats and node status

How the cluster notices a dead kubeletrenew, 10sstatuswatchesReady: Unknownadds taintkubeleton node01Lease node01kube-node-leaseNode controllercontroller managerNode node01Ready conditionTaint, then evictunreachable:NoExecute
How the cluster notices a dead kubelet. The kubelet renews a small Lease object every 10 seconds. When the renewals stop, the node controller marks the node Unknown and taints it; Pods are replaced only after their toleration runs out.

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-lease namespace 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 serverStatic Pods
Defined inThe API (created by you or a controller)A file in the kubelet's staticPodPath
Needs a control planeYesNo, only the kubelet and the runtime
Placed byThe schedulerNobody: always on the node that holds the file
Visible in kubectlYesYes, as a read-only mirror Pod named <name>-<nodeName>
Change or removekubectl edit, kubectl deleteEdit, 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

Where a kubeadm kubelet gets its settings--configextra flags--kubeconfigsystemdkubelet.service10-kubeadm.confdrop-in: builds flagsconfig.yaml/var/lib/kubeletkubeadm-flags.env/var/lib/kubeletkubelet.conf/etc/kuberneteskubelet/usr/bin/kubelet
Where a kubeadm kubelet gets its settings. systemd starts the kubelet with flags built by a drop-in file. The flags point at three files, and a mistake in any link of this chain keeps the kubelet from starting.

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:

FileWhat it holds
/usr/lib/systemd/system/kubelet.serviceThe base systemd unit
.../kubelet.service.d/10-kubeadm.confThe drop-in that builds the real command line (the binary path and the flags below)
/var/lib/kubelet/config.yamlThe KubeletConfiguration: almost every setting, including staticPodPath, clusterDNS, cgroupDriver, the client CA file and eviction thresholds
/var/lib/kubelet/kubeadm-flags.envA few flags that differ per node, written by kubeadm init and kubeadm join
/etc/kubernetes/kubelet.confThe 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
  • cgroupDriver must match the container runtime's driver. On systemd machines both should be systemd (kubeadm's default). A mismatch gives an unstable node or a kubelet that refuses to start.
  • clusterDNS is written into every Pod's /etc/resolv.conf. If it does not match the ClusterIP of the kube-dns Service, Pods start fine but cannot resolve any name.
  • clientCAFile is 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-config in kube-system. kubeadm join and kubeadm upgrade node write 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 kubelet starts 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 to config.yaml in the drop-in, a bad value in config.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 kubelet and its logs are in journalctl -u kubelet, on the node itself.
  • Forgetting daemon-reload. After editing a unit or drop-in file, systemd keeps using the old version until systemctl daemon-reload. Edits to config.yaml need only a restart.
  • Starting without enabling. systemctl start kubelet fixes the node until the next reboot. Use systemctl enable --now kubelet.
  • Fixing the wrong node. kubectl runs from where you are, but systemctl and the files act on the machine you are logged in to. Check the prompt before you edit anything, and exit when 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-reload and 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 Ready or NotReady; 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-reload if 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.