Chapter 1 of 47 · Start here

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
You run every container yourselfYou type three docker run commands. Each starts one container on one machine.Youdocker run × 3postsuserscomments
Three containers, three commands. Easy.

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:

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:

Kubernetes manages your containers for you.

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.

Kubernetes keeps three copies runningLeft: Kubernetes runs posts-1, posts-2 and posts-3. Middle: posts-2 crashes. Right: Kubernetes notices it should have three and creates posts-4. 1 · You ask for 3 Kubernetes posts-1 posts-2 posts-3 2 · One crashes posts-1 posts-2 ❌ posts-3 3 · It is replaced posts-1 posts-3 posts-4 (new) Kubernetes notices: "I should have 3, I have 2."So it creates one more. Nobody had to wake up.
This is the core idea of Kubernetes: you say how many, it keeps that many.

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

Quick check

You asked Kubernetes for 3 copies of posts. One crashes. What does Kubernetes compare to decide what to do?
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.