How Kubernetes works: Desired state and reconciliation
Kubernetes is not a script runner. It is a set of control loops that compare what you asked for with what is running, and fix the gap.
By Gilaburu · · 6 min read

Most people meet Kubernetes through YAML and kubectl apply, and it can feel like a very verbose way to start containers. The real idea is simpler and more powerful than that: you describe the state you want, and the system works continuously to make reality match it. Everything else in Kubernetes follows from that one design choice.
This post is part of our Foundations series. It is the mental model we wish we had when we started, and the one behind Kelp, our CLI for working across many namespaces.
Imperative versus declarative
There are two ways to run software on a fleet of machines.
Imperative: you give orders. "Start three copies of the web server on these hosts. If one dies, start another." A script or a person carries out each step, and if something fails halfway, someone has to notice and clean up.
Declarative: you describe the result. "There should always be three copies of the web server running, version 1.4." You do not say how to get there or what to do when a machine dies. The system figures that out, and keeps figuring it out forever.
Kubernetes is declarative. Here is what that looks like:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3 # desired state: three copies
selector:
matchLabels: { app: web }
template:
metadata:
labels: { app: web }
spec:
containers:
- name: web
image: ghcr.io/example/web:1.4
When you apply this file, nothing "runs" it from top to bottom. It is stored as a record of intent. Then a set of independent processes notice the new record and start moving the cluster towards it.
The pieces of a cluster

A cluster has two halves. The official Kubernetes components overview describes each one in detail; here is the short tour.
The control plane is the brain:
- API server (
kube-apiserver). The front door. Every read and write, fromkubectl, from your CI pipeline and from Kubernetes' own components, goes through it. It validates requests and stores them. - etcd. A consistent, distributed key-value store. It holds the whole state of the cluster: every Deployment, Pod, Service and Secret. If etcd is healthy and backed up, the cluster can be rebuilt.
- Scheduler (
kube-scheduler). Watches for Pods that have no node yet, and picks the best node for each one based on resources, affinity rules and constraints. - Controller manager (
kube-controller-manager). Runs dozens of built-in controllers, each responsible for one kind of object. More on these in a moment.
Worker nodes are the muscle:
- kubelet. An agent on every node. It asks the API server "which Pods should be on me?", starts them through the container runtime, and reports back how they are doing.
- Container runtime. The software that actually runs containers, such as containerd or CRI-O.
- kube-proxy. Programs the node's networking so that a Service's stable address reaches the right Pods.
Notice what is missing: no component tells another component what to do. They do not call each other directly. They all read and write shared state through the API server, and each one reacts to what it sees.
The reconciliation loop
The core pattern is the controller. The Kubernetes documentation compares it to a thermostat: you set the temperature you want (desired state), the thermostat measures the room (actual state), and it switches the heating on or off to close the gap. It never "finishes". It just keeps checking.

Every controller runs the same loop:
- Observe. Watch the API server for changes to the objects it owns.
- Diff. Compare the desired state (the object's
spec) with the actual state (itsstatus, and the world). - Act. Make one change that moves reality closer to the spec: create a Pod, delete a Pod, update a record.
- Repeat. Write the new status back, and go around again.
Follow our Deployment through the system and you can see several loops hand work to each other:
- You apply the Deployment. The API server stores it in etcd.
- The Deployment controller sees a Deployment with no ReplicaSet, and creates one.
- The ReplicaSet controller sees a ReplicaSet that wants three Pods and has zero, and creates three Pod records.
- The scheduler sees three Pods with no node, and assigns each one to a node.
- The kubelet on each chosen node sees a Pod assigned to it, and starts the container.
Now pull the power cable on one node. Its kubelet stops reporting. The node controller marks the node as not ready and, after a grace period, its Pods are evicted. The ReplicaSet controller now counts two healthy Pods instead of three, and creates a new one. The scheduler places it elsewhere. Nobody wrote a "recover from node failure" script. Recovery is just the normal loop seeing a gap.
This is also why changes are safe to repeat. Applying the same file twice does nothing the second time, because there is no difference to fix. Engineers call this property idempotence, and it is what makes GitOps tools such as Argo CD and Flux possible: they simply keep the cluster's desired state in sync with a Git repository.
Where the idea came from
Kubernetes was open-sourced by Google in 2014, built by engineers who had spent a decade running Google's internal cluster managers, Borg and Omega. The paper Borg, Omega, and Kubernetes (Burns, Grant, Oppenheimer, Brewer and Wilkes, ACM Queue, 2016) explains which lessons they carried over. Two stand out:
- Put all state behind one API, and let many small, independent controllers work on it, instead of one big central brain. It is easier to extend and survives partial failures better.
- Use labels, not fixed groupings. A ReplicaSet does not own a list of Pods; it owns "whatever Pods carry the label
app: web". That loose coupling is what lets the controllers above cooperate without knowing about each other.
Extending Kubernetes with your own loops
Because the pattern is so regular, you can add your own. A Custom Resource Definition (CRD) teaches the API server a new kind of object, say Database or Tenant. An operator is a controller you write that reconciles those objects: it sees a Database with replicas: 3 and does whatever it takes to make that true, including backups and upgrades. Tools such as Kubebuilder generate most of the boilerplate.
This is the foundation of much of modern platform engineering: teams wrap their company's best practices in custom resources, so a developer can ask for "a production-ready service" in ten lines of YAML and the platform's controllers do the rest. We will write about that in a later post.
Takeaways
- Kubernetes stores intent, not commands. You declare the desired state; you do not script the steps.
- Many small controllers each run an observe, diff, act loop against the API server. Self-healing is a side effect of that loop, not a separate feature.
- Components never call each other. They coordinate through shared state in etcd, behind the API server.
- You can add your own resources and controllers, and that is how most platforms on Kubernetes are built.
Next in this series: namespaces, multi-tenancy and how to give many teams one cluster without letting them step on each other.
Sources and further reading
- Kubernetes documentation, Kubernetes components
- Kubernetes documentation, Controllers
- B. Burns, B. Grant, D. Oppenheimer, E. Brewer, J. Wilkes, Borg, Omega, and Kubernetes, ACM Queue 14(1) (2016)
- A. Verma et al., Large-scale cluster management at Google with Borg, EuroSys (2015)
- The Kubebuilder Book, Kubebuilder
Get new posts by email
A short note in your inbox when we publish, with a link to the full post here. Free, sent through Substack.
Read on Medium? Follow us there
See more of our posts in Google Top Stories.

