Kubernetes Explained: Who Restarts Your App When a Machine Dies?
What the video says
A machine dies at 3 a.m.
It is 3 in the morning, and a machine dies. Your app was running on it. A few minutes later the app is whole again, and nobody woke up. So who fixed it?
Containers made an app easy to start. But someone still has to notice a dead one, and start it again somewhere else. Google had built a system for that, called Borg. Kubernetes descends from it. It was announced on June 10, 2014, and version 1.0 arrived on July 21, 2015.
Write down the state you want
With Kubernetes you do not give orders. You write down the state you want: 3 copies running. Then the controller keeps going around its loop, comparing what is with what should be. The documentation gives one example: the thermostat in your room, which acts to bring the current state closer to the desired state.
The scheduler and the kubelet
Every copy needs somewhere to run. The scheduler looks for copies not yet bound to a machine, and assigns each one to a suitable machine, one with room.
On every machine sits an agent, the kubelet. It makes sure its copies are running, and it keeps reporting that the machine is alive: a heartbeat. By default, those are checked every 5 seconds.
When a machine goes silent
Now one machine goes silent. By default, after 50 seconds without a heartbeat, it is marked unhealthy. Its copies stay bound to it for 300 seconds more, then they are given up. The sum is my own arithmetic: 350 seconds, almost 6 minutes. What happens next follows from the loop. The count is below 3, so new copies are made, and the scheduler places them on machines that still answer.
Why not a person, or a script?
Why not something simpler? A person on call, paged at 3 a.m., restarting things by hand, is slow and tired. A startup script on each machine can restart a copy that crashed. But when the whole machine is gone, the script is gone with it, and it cannot move work anywhere else.
In practice: replicas: 3
In practice, the wish is a few lines of text called a Deployment. One line says replicas: 3. You hand that over, and the loop does the rest.
So that is Kubernetes. You declare what should be true, and a loop makes it true, again and again.
Subscribe for the next one. Next time: caching. Why is the second visit so much faster?
Sources
Every fact in the video was checked against these when it was made.