Control plane
Reconcile loops
Desired vs. actual state
Delete a Pod by hand and watch the ReplicaSet controller put it back. Underneath that party trick is the pattern the whole control plane runs on: watch the world, diff desired against actual, act, report. It's level-triggered - reacting to state, not events - which is why it survives crashes and works whether the change came from you, a bug, or a dead node.
- Command
- kubectl delete pod web-…-p8m4z
- Owner
- ReplicaSet web-6f7c9d8b4 · wants 3
- Pattern
- watch → diff → act → report
- Trigger
- level-triggered, not edge-triggered
Read the whole lesson as text
1. The pattern
Pick any controller - ReplicaSet, Deployment, EndpointSlice, node lifecycle - and you'll find the same four-beat loop. Watch: the informer cache holds the world. Diff: desired state from spec, actual from status and live Pods. Act: POST, PATCH or DELETE until actual matches desired. Report: write status back for humans and other controllers. Then sleep until the world changes.
- Right now the loop is idle: desired 3, actual 3, nothing to do.
2. You delete a Pod
You delete web-…-p8m4z - maybe debugging, maybe tidying. Two things start at once: the API marks the Pod with a deletionTimestamp, and node-2's kubelet sees it and tears the container down politely. The Pod object lives those few seconds in Terminating. The ReplicaSet controller doesn't care yet; it counts non-terminating Pods, and this one just left the count.
- You delete one Pod out of three.
- node-2's kubelet does the actual work of stopping the container.
3. The controller notices
The ReplicaSet controller's informer delivers the update - deletionTimestamp set - but the decision doesn't depend on the event itself. Counting its Pods: owned (ownerReferences → web-6f7c9d8b4), matching labels, not terminating. That's 2. Desired is 3. The diff is −1, so the act is one create. The controller never asks who deleted it or why; a hand-delete, an OOM, or a dead node all read identically here.
- The controller hears about the deletion like everyone else - through its watch.
- It counts what it owns and finds one short.
4. The replacement
The controller creates web-…-t4c8e - not a resurrection, a newborn: new random suffix, new UID, no memory of the old one. Identity is not a Deployment's product. The scheduler places it on node-2: spreading is a tie now, one web Pod each, and node-2 has more free room. Same node as before, but node-2's kubelet starts it like any first Pod: sandbox, new IP, image already cached, container.
- One create, sized exactly to the diff.
- The scheduler picks node-2 for the replacement.
5. Converge and report
Two seconds later web-…-t4c8e is Running and Ready. The controller's next pass counts 3 and 3, writes status.readyReplicas=3, and sleeps. Two properties of the pattern are worth holding: if the controller had crashed mid-loop, nothing would be lost - the next pass re-diffs the world; and nothing ever commanded the kubelet - each component discovered its own next step through the API. Self-healing is nobody's job; it's the shape of the loop.
- The replacement passes its probe and reports Ready.
- The controller writes the final count and goes back to sleep.
Summary
Desired minus actual, applied with creates and deletes until the answer is zero. The loop doesn't know or care what caused the drift - your delete, an OOM, a node dying - which is exactly why the same three lines of arithmetic scale up to the whole control plane. Every controller is this lesson wearing a different resource.
Next lesson: A node goes dark