Topic 181 / Advanced
Kubernetes architecture
Chapter 11.3 · Kubernetes
What and why
Running a handful of containers (→ 180) by hand — pick a host, start it, watch it, restart it if it dies — stops working once a system has dozens of services across many hosts that must be placed, restarted, and rebalanced continuously. Kubernetes is a container orchestrator: a control plane that takes a declarative description of desired state ("run 5 copies of this image, healthy, across these hosts") and continuously reconciles actual cluster state toward it. Builds on: → 180 (Docker and containers).
Diagram
Control plane Nodes
┌─────────────────────────┐ ┌──────────────────────┐
│ API server ◄──────────────────────► │ kubelet │
│ │ │ │ container runtime │
│ ▼ │ │ running pods ×N │
│ etcd (→ 136) │ └──────────────────────┘
│ scheduler │ ...repeated per node
│ controllers (reconcile) │
└─────────────────────────┘
How it works
- Every change — deploy a new version, scale up, update config — is submitted as a desired-state object to the API server, the single point every other component reads from and writes through.
- etcd (→ 136, a coordination service) stores that desired state, and the control plane's view of actual state, durably and consistently — it is the cluster's single source of truth; losing it is losing the cluster's memory of what should be running.
- The scheduler watches for newly created workload objects with no node assigned and picks a node for each, based on resource requests (→ 183) and constraints.
- Controllers continuously compare desired state against observed actual state and act to close any gap — if a node dies and takes 3 pods with it, the relevant controller notices and schedules 3 replacements elsewhere, with no human in the loop.
- Each node runs a kubelet (the agent that starts, stops, and reports on the containers the control plane assigned to it) and a container runtime that actually runs them.
- This reconciliation loop — desired state in, actual state observed, difference corrected, repeat — is the single mental model for everything Kubernetes does; there is no imperative "do this now and don't check again."
Practical example
(numbers illustrative). An operator declares "5 replicas of this image, healthy." A node carrying 2 of those replicas fails. The relevant controller observes actual state has dropped to 3 against a desired 5, and schedules 2 new pods on healthy nodes — typically restoring full capacity within the time it takes to place and start them, often under a minute, with zero manual intervention. The same reconciliation that recovers from a node failure is what executes a deliberate scale-up: the operator changes the declared count, and the same gap-closing logic runs identically either way.
When to use it
- Use Kubernetes once the number of services, hosts, or deployment frequency makes manual placement and recovery untenable, and the team has — or will build — the operational skill to run it.
- Use it when workload portability across infrastructure (cloud, on-prem, multi-cloud) genuinely matters.
- Avoid Kubernetes for a small number of services a managed container platform already schedules and heals adequately — the control plane itself is infrastructure that must be learned, secured, and, if self-managed, upgraded.
- Failure scenarios: running Kubernetes without understanding the reconciliation model and fighting it with imperative one-off changes the next reconcile silently reverts; a team adopting it for "best practice" reasons with no operational investment, then spending more time debugging the orchestrator than the workloads it runs; etcd itself becoming unavailable or corrupted — the whole cluster's control loop stalls, because etcd is the one piece with no higher layer to reconcile it.
- Simpler alternative: rule 7's load-bearing case here — a managed container service with a deploy script, or a handful of VMs behind a load balancer with a simple health-check-and-restart script, runs a small number of services with a fraction of the operational surface Kubernetes requires. Reach for Kubernetes only once that simpler setup is demonstrably the bottleneck.
Practice
(trace kind, 20–30 min, conceptual — no cluster required; an optional local single-node cluster works too, if you already run one). Trace, step by step, what happens from "an operator submits a 5-replica Deployment" through "pods are scheduled and running," then trace the failure path: "one node dies" through "replacement pods are running elsewhere" — name the concrete component acting at each step and what it's watching for. Done when both traces name a specific component, not "Kubernetes," at every step.
Key takeaway
Kubernetes is a control plane that continuously reconciles declared desired state against actual cluster state; every feature — scaling, healing, rolling updates — is the same reconciliation loop applied to a different kind of gap. Done when you can: trace a pod's path from declaration to running, and from a node failure to recovery, naming the responsible component at each step. Used next in → 182 (the workload, networking and storage objects this control plane manages), → 183 (how it decides a pod is healthy and how much to give it).
References
Kubernetes: Concepts — see references.md.