Why you need it
Copies of an app crash, often at night. If a person has to notice and start a new one, the app stays broken until someone wakes up. And a person who changes things by hand soon forgets what was meant to be running at all.
Think of it like this
A shelf in a supermarket with a card that says "keep 12 cans here". A worker walks past every few minutes, counts, and tops it up. Nobody tells them a can was sold; they just compare the shelf with the card.
Where you’ll find it
- Kubernetes: Is built from controllers: small loops that each compare what you asked for with what runs, and fix the gap.
- AWS: EC2 Auto Scaling keeps a group at its set size, replacing any server that fails its health check.
- Argo CD and Flux: Keep a cluster matching the files in a Git repository: Argo CD and Flux.
What to know first
Scheduler. The program that picks a server for each new copy. See Scheduling.
Health check. A regular question to each copy, so a crashed one is noticed fast. See Health checks and heartbeats.
Desired state. What should be running, written down, for example replicas: 3. The number in the code.
How it works
- Write down the goal. Instead of starting copies by hand, you write how many should run. This is the number in the code in the animation.
- Look, compare, act, repeat. A controller counts the copies that are running and healthy, and compares with the number in the code. Too few: start more. Too many: stop some. Then it looks again, forever.
- A crash is just a gap. When a copy crashes, the count drops below the number. The controller sees the gap and starts a new copy. This is the reconciliation in the animation, at 3:00 at night with nobody awake.
- A change is also just a gap. To get more copies, Ben changes the number from 2 to 3. He does not start anything himself. The controller sees 2 running, 3 wanted, and adds one.
- Compare the whole picture. The controller does not depend on hearing about each crash. It checks the full count every time, so a missed message or a restart of the controller itself does no harm: the next look fixes it.
An example
The code says 3 copies. At 3:00 one crashes. A health check every 5 seconds notices within about 15 seconds.
The controller sees 2 running, 3 wanted. It asks for a new copy, which starts in about 20 seconds.
The shop is short one copy for under a minute, instead of six hours until Ben wakes at 9:00.
Further reading
- Controllers, Kubernetes docs. The control loop, explained in one short page. Start with this one.
- Borg, Omega, and Kubernetes, Burns, Grant, Oppenheimer, Brewer and Wilkes, ACM Queue. Google engineers on why many small loops beat one big plan.
- OpenGitOps principles, OpenGitOps, CNCF. Four short rules for keeping the desired state in Git and reconciling to it.