Why Kubernetes?
You already know Docker. This chapter is about the moment Docker alone stops being enough, and what Kubernetes does about it. No commands to memorise yet.
Docker on one machine
Say your app is three small services: posts, users and comments. With Docker you start each one yourself:
$ docker run -d --name posts micro-posts
$ docker run -d --name users micro-users
$ docker run -d --name comments micro-comments
When there are hundreds
Production is different. You do not run one posts, you run several copies on several machines, and the number keeps growing: 10 containers, then 100, then 500. Now somebody has to answer these questions, all day, every day:
- A container crashed at 3 a.m. Who restarts it?
- How do I run 5 copies of
posts? - How is traffic shared between those copies?
- How do containers find each other when their IPs keep changing?
- How do I ship a new version without downtime, and roll back if it is broken?
- How do I go from 5 copies to 20 when traffic spikes?
With Docker alone, the answer to every one of them is "you, by hand". That is the problem Kubernetes solves.
What Kubernetes is
Kubernetes is a container orchestration system. Do not worry about the word. It means:
Instead of starting containers yourself, you tell Kubernetes what you want, for example "I want 3 copies of my posts application running". Kubernetes makes sure there are 3, and it keeps checking.
Try it: crash a copy
This is a pretend cluster running 3 copies of posts. Press Crash on any of them and watch Kubernetes put the count back. Crash two at once if you like.
Notice two things. The new copy gets a new name and a new IP address; it is a replacement, not a repair. And you never told Kubernetes how to fix it. You only told it how many you wanted.
Recap
- Docker builds and runs containers. With a few, doing it by hand is fine.
- With hundreds of containers, restarting, scaling, sharing traffic and updating by hand stops working.
- Kubernetes is a container orchestrator: it manages containers for you.
- You describe what you want ("3 copies"), and Kubernetes keeps reality matching it.
Quick check
Show answer
What you asked for (3) with what is actually running (2). Because they differ, it creates one new copy until both are 3 again.
Why Kubernetes: common questions
What is Kubernetes in simple words?
A system that manages your containers for you. You say what you want, for example 3 copies of an app, and Kubernetes keeps exactly that many running, replacing any that crash.