Kubernetes: desired state and reconciliation
How Kubernetes keeps what was declared: API server, etcd, controllers and the scheduler as control loops; Pods, ReplicaSets, Deployments, Services; rollouts; requests, limits and probes.
Desired state and the loop
Scripts that ssh and docker run fail at placement, healing, rollouts, service addresses and multi-tenant isolation once you have dozens of machines. Key idea: store objects with spec (desired) and status (observed). Controllers reconcile forever: observe, compare, act, write status. The loop is level-triggered — it reacts to the gap between desired and observed, not to unmissable edge events. Missed events are fine; the next resync still sees "want 3, have 2" and creates a Pod. Borg and Omega used the thermostat analogy for the same reason.
Path of a Deployment apply: kubectl apply → API server persists to etcd → Deployment controller creates or updates a ReplicaSet → ReplicaSet creates Pods → scheduler binds Pods to nodes → kubelets pull images and start containers via CRI → readiness flips → status flows back up. If a Pod dies, the ReplicaSet sees too few replicas and creates another — healing without a human. If you delete a Pod you did not want deleted, the same loop recreates it; change the Deployment spec or scale to zero if you want it gone.
Reconciliation is eventually consistent. Briefly "wrong" states during rollouts are normal; design readiness probes and PodDisruptionBudgets so "briefly wrong" does not equal "serving errors."
The control plane
API server — the only component that talks to etcd; authentication, authorization, admission webhooks; watch streams for controllers. etcd — Raft consensus; quorum . For 5 members that is 3 — survive losing two. Four members also need quorum 3, so they tolerate only one loss (same as three); prefer odd sizes. Controller manager runs the built-in reconcilers; scheduler binds Pods to nodes; kubelet on each node runs pods via CRI; kube-proxy or eBPF dataplanes program Service routing.
Components do not RPC each other as a mesh of special protocols; they read and write API objects. That design is why CRDs work: your controller is just another reconciler watching a new kind. Control-plane capacity is an ops number: a busy cluster with thousands of watches stresses the API server; rate-limit noisy clients; keep etcd disks fast and backed up — etcd loss is cluster amnesia.
Objects
A Pod is mortal and scheduled as a unit (one or more containers sharing namespaces). Never treat a Pod name as durable identity. Labels and selectors glue ReplicaSets and Services to Pods without listing names — change labels carefully or you orphan or double-select. A Deployment owns ReplicaSets (one per template hash) and keeps rollout history for rollback. A Service gives a stable virtual IP and DNS name (web.shop.svc.cluster.local); endpoints track ready Pods. Namespaces scope names, RBAC and quotas — they are not a network security boundary by themselves (see NetworkPolicy in the next topic).
Resource requests influence packing: a node with 4 CPU and 8 Gi can place four Pods that request 900 mCPU and 1.5 Gi, but a fifth will not schedule even if actual usage is low. Oversized requests waste money; undersized requests invite throttling and OOM kills under burst.
Rolling update arithmetic
Defaults maxSurge / maxUnavailable of 25% on 4 replicas: surge , unavailable → at most 5 Pods during the rollout, at least 3 available. New Pods count toward availability only after the readiness probe passes — a slow readiness with aggressive rolling is how you take the Service below capacity while the Deployment reports progress.
Worked exposure. 20 replicas, 25% surge/unavailable → surge 5, unavailable 5 → as few as 15 serving. If peak needs 18, that rollout is an incident. Either raise replicas before the deploy, tighten maxUnavailable to 0 (pay with slower rollouts and more surge capacity), or canary with a separate Deployment and traffic split.
Resources and probes
Set requests (what the scheduler reserves) and limits (cgroup max). CPU limits throttle; memory limits OOM-kill. Readiness gates Service traffic — fail readiness to drain without killing. Liveness restarts containers the kubelet thinks are dead; startup delays liveness during slow boots (JVM, large image pulls). Mis-set liveness on a temporarily overloaded process turns a latency incident into a restart storm: every Pod fails liveness, restarts, stampedes dependencies, fails again.
Probe timeouts and periods are concrete: a readiness periodSeconds: 5 with failureThreshold: 3 can take ~15 s to remove a bad Pod from rotation — similar math to load-balancer health checks. Align them so Kubernetes and the external balancer are not fighting.
Admission webhooks and validating policies extend the reconcile model: reject Pods that lack requests, that run as root, or that pull from untrusted registries before they are persisted. Mutating webhooks can inject sidecars and defaults; keep them boring and idempotent — surprising mutations fight GitOps diffs and human review.
Cluster upgrades are controlled rollouts of the control plane then nodes. Drain with PDBs respected; verify that surge capacity exists before cordoning a zone's worth of nodes. The same rolling math that protects application Deployments applies to the nodes they sit on — treat node pools as another layer of desired state.
Next: Kubernetes in practice — ConfigMaps and Secrets, Ingress, Jobs, HPA and the packing habits that keep clusters boring.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Go deeper — optional
Code and labs do not count toward the main percentage or the certificate.
- Replica reconciliation loopoptional
Desired=3, current=2+CrashLoop: what the Deployment/ReplicaSet controller does on the next tick.
~20 min · easier on a computer · The matching course topic has been read.
Self-check in the notebook — not part of mastery or the certificate.
Answers are saved on the server and tied to this browser until you sign in.