Skip to Content

Kubernetes Field Guide · Chapter 1 of 16

Why Kubernetes: the problems Docker leaves you with

Start here, even if you have never touched a cluster. How we got from one app per server to containers, what Docker solved, the problems it leaves you with at 3am, and the one idea Kubernetes is built on.

  • 35 min
  • Beginner
  • Hands-on
  • Free

By , founding engineer running Kubernetes in production. Updated .

You, at 3amssh, docker run, edit configserver-1web?server-2web ✕server-3web?Docker aloneyou are the control loopdesired stateweb × 3, nginx:1.27node-1webnode-2evictednode-3webweb newWith Kubernetesobserve, compare, fix: forever
The chapter in one pictureDocker runs containers. Kubernetes keeps them running the way you described, without you.

By the end you can

0 of 5

How we got here

Kubernetes makes sense once you see the problem it was built for, and that problem only appeared after a few earlier fixes. Step through four eras of running software. Each one fixes the last one's problem and creates a new one.

server-1physicalidleshopLinux + librarieshardwareserver-2physicalidlebillingLinux + librarieshardwareserver-3physicalidleemailLinux + librarieshardware

Nothing to fix yet: you buy a server, install the OS, install your app.

New capacity
Weeks: order and rack a server
Apps per server
One, to avoid conflicts
Typical load
Mostly idle

New problem Servers sit mostly idle, apps fight over library versions, and "it works on my machine" is a daily sentence.

1 of 4

Every picture in this guide uses the same colours, so you can read a diagram before you read its labels:

  • Machines: servers and nodes
  • Your app and its containers
  • Kubernetes objects, healthy
  • Control plane and controllers
  • Traffic and warnings
  • Failures

What Docker solved, and what it did not

A container image is your app plus everything it needs to run: the runtime, libraries and config defaults, frozen into one file. A container is that image running as an isolated process. Docker made both easy: docker build makes the image, docker run starts it, and it behaves the same on your laptop and on a server.

That is a packaging solution. Look at what docker run actually promises: one container, on this machine, now. It knows nothing about your other servers, whether the app is healthy, or how many copies you wanted.

Dockerone machineDockerfileimagecontainerbuild, ship, runsameimageKubernetesmany machines, one desired stateplacerestartmovescaleupdateroutenode-1containerdwebapiworkernode-2containerdwebapinode-3containerdwebapiworker
Two different jobsKubernetes does not replace your images. It runs the same images, on many machines, and keeps them the way you described.

Once you run more than one server, someone has to answer the questions docker run does not: which server has room, what happens when one dies, how traffic finds the new copy, how to swap versions without dropping requests. Teams answer them with scripts, cron jobs and a runbook. Kubernetes replaces that pile with one system.

The 3am test: Docker vs Kubernetes

The easiest way to feel the difference is to break things. Pick an incident and play it on both setups at once: three servers running Docker, and a three-node Kubernetes cluster running the same app. Watch who does the work, and how long the app is unhealthy.

Interactive · The 3am test

Same incident, two setups. Pick one and press Play.

Docker on 3 servers

03:12

Serving

    Kubernetes, 3 nodes

    03:12

    Serving

      Notice the pattern. Docker is good at the one machine it runs on. Everything that spans machines, or needs a decision, falls to you. Kubernetes moves those decisions into software that never sleeps.

      Desired state and the reconcile loop

      With Kubernetes you stop giving instructions ("start a container on server 2") and start describing an outcome: three copies of web, image nginx:1.27. That description is the desired state.

      Small programs called controllers then run a loop, forever: observe what is actually running, compare it with what you asked for, and act on the difference.

      observecompareactforeverevery few secondsdesiredwhat you wrotewebwebwebactualwhat is runningwebweb?difference1 pod missingcreate 1
      The reconcile loopEvery controller in Kubernetes is this loop, watching a different kind of object.

      If a container dies, actual state drifts from desired state, and a controller fixes it. Nobody has to notice. Try it: kill containers, fail a node, change the replica count. Then switch to plain Docker and do the same.

      Interactive

      Desired state vs actual state

      replicas: 3

      desired 3running 3in sync

        Click a container to kill it. Switch modes and compare who notices.

        What Kubernetes takes off your hands

        Everything in this guide is one of these jobs, done by a controller watching desired state. Each links to the chapter that covers it.

        • Placing containers on serversYou pick a server with roomThe scheduler · chapter 2
        • Restarting crashed containersRestart policy, one host onlyKubelet and ReplicaSets · chapter 4
        • Recovering from a dead serverRebuild and redeploy by handPods rescheduled elsewhere · chapter 4
        • Scaling up and downStart more containers by handReplicas and the autoscaler · chapter 9
        • Deploying without downtimeA deploy script you maintainRolling updates and rollbacks · chapter 4
        • Finding other servicesHard-coded IPs in env filesServices and cluster DNS · chapter 5
        • Config and secretsEnv files copied to each serverConfigMaps and Secrets · chapter 6
        • Knowing an app is healthyA check on the load balancerLiveness and readiness probes · chapter 10

        Do you need Kubernetes?

        Kubernetes has real costs: a control plane to run or pay for, upgrades every few months, networking and storage to understand, and a learning curve for everyone who touches it. It earns that cost when you have many services, deploy often, or create and destroy environments on demand. Answer for a system you know:

        Interactive

        Do you need Kubernetes? Answer for your own system.

        How many services do you run?
        How often do you deploy?
        Do you create environments on demand (per customer, pull request or user)?
        Who will run the platform?
        1. One VM with Docker Compose

          Cheapest. One bill, nothing new to learn.

          A small, steady system does not need a scheduler. Back up the VM, put a load balancer in front if you need two.

        2. A managed container service

          AWS ECS or Fargate, Google Cloud Run, Azure Container Apps.

          You get restarts, scaling and rolling deploys without running a control plane or learning Kubernetes.

        3. Kubernetes

          Managed (EKS, AKS, GKE), or K3s on your own servers (chapter 13).

          Many services, frequent changes or on-demand environments are exactly what it is built for. The learning curve pays for itself.

        A rule of thumb, not a law. Teams also pick Kubernetes to learn it, to match a client's stack, or because they already run it.

        Hands-on: your first cluster

        Live lab · no install

        Your first cluster, in the browser

        Create a Deployment, delete its pods and watch Kubernetes put them back.

        kind-learn
        1. Tasks0/6
        2. Meet your cluster

          A kind cluster is already running. It has one node that is both control plane and worker.

          kubectl get nodes

          One node, Ready. Everything you create will run on it.

        3. Declare desired state: 3 copies of nginx

          You describe what you want. You never say how to start containers.

          kubectl create deployment web --image=nginx:1.27 --replicas=3

          Watch the map: three pods went from dashed (starting) to solid (ready).

        4. Break it: delete one pod

          Click a pod in the map to paste its name, or use the one-liner.

          kubectl delete $(kubectl get pods -l app=web -o name | head -n 1)

          Gone. Now look at the map.

        5. Watch it heal

          The reconcile loop noticed 2 instead of 3 and made a new pod. Its name is new and its age is seconds.

          kubectl get pods -l app=web

          Self-healing is not magic: it is a loop comparing desired with actual.

        6. Change your mind: scale to 5

          Changing desired state is one command. The same loop does the work.

          kubectl scale deployment web --replicas=5
        7. Delete two at once, then scale back to 3

          Predict first: how many pods will you see a few seconds later?

          kubectl delete $(kubectl get pods -l app=web -o name | head -n 2)
          kubectl scale deployment web --replicas=3

          The loop runs in both directions: it creates missing pods and removes extra ones.

        8. Lab complete. Keep experimenting, or press Reset to start again.
        ↑↓ history · Tab complete · Ctrl+C stop
        Cluster map live
        • ready
        • starting / not ready
        • failing
        • terminating
        Prefer your own machine? The same steps on a local cluster

        kind (Kubernetes in Docker) runs a whole cluster inside Docker on your laptop. It is free, starts in under a minute and is what every chapter in this guide uses. You need Docker running first.

        Install (macOS with Homebrew)
        brew install kind kubectl
        
        kind
        Creates clusters whose nodes are Docker containers.
        kubectl
        The command-line client for any Kubernetes cluster.

        On Linux or Windows, follow the kind installation guide and the kubectl install page.

        Create a cluster
        kind create cluster --name learn
        kubectl get nodes
        NAME                  STATUS   ROLES           AGE   VERSION
        learn-control-plane   Ready    control-plane   45s   v1.34.0
        --name learn
        Names the cluster. kubectl is pointed at it automatically (context kind-learn).
        get nodes
        One node that is both control plane and worker. Your version may differ.

        Now declare some desired state: three copies of nginx.

        Terminal
        kubectl create deployment web --image=nginx:1.27 --replicas=3
        kubectl get pods -l app=web
        NAME                   READY   STATUS    RESTARTS   AGE
        web-6c9b8d7f5d-4xk2p   1/1     Running   0          12s
        web-6c9b8d7f5d-9qmzt   1/1     Running   0          12s
        web-6c9b8d7f5d-tw7rc   1/1     Running   0          12s
        create deployment web
        Records desired state: a Deployment named web.
        --replicas=3
        How many copies should exist at all times.
        -l app=web
        Filter by label. create deployment labels its pods app=web.

        Delete one pod and watch the reconcile loop replace it.

        Terminal
        kubectl delete $(kubectl get pods -l app=web -o name | head -n 1)
        kubectl get pods -l app=web
        pod "web-6c9b8d7f5d-4xk2p" deleted
        NAME                   READY   STATUS    RESTARTS   AGE
        web-6c9b8d7f5d-9qmzt   1/1     Running   0          2m
        web-6c9b8d7f5d-tw7rc   1/1     Running   0          2m
        web-6c9b8d7f5d-zc8hn   1/1     Running   0          3s
        -o name
        Prints pod/NAME, which kubectl delete accepts directly.
        zc8hn, 3s
        A brand-new pod. The old one is gone for good; its replacement has a new name.

        Mini mission

        Scale it, then break it

        Scale web to five replicas. Predict what happens if you delete two pods at once, then do it and watch with -w. Finally, scale back to three.

        Reveal one safe solution
        Terminal
        kubectl scale deployment web --replicas=5
        kubectl delete $(kubectl get pods -l app=web -o name | head -n 2)
        kubectl get pods -l app=web -w
        kubectl scale deployment web --replicas=3
        

        Two new pods appear within seconds, so you are back to five. Scaling down to three makes the controller delete two: the same loop, in the other direction. Press Ctrl+C to stop watching.

        Check yourself

        Quiz

        0 of 5 answered

        1. 1. What problem did containers solve that virtual machines did not?
        2. 2. A server running three of your Docker containers loses power. What brings those containers back?
        3. 3. What does kubectl apply do first?
        4. 4. A Deployment wants 3 replicas. You delete one pod. What happens?
        5. 5. When is Kubernetes most likely overkill?

        Further reading