What Is Kubernetes? A Beginner's Guide with Analogies
Picture the app from the Compose lesson a year later: ten containers on three servers. One night a server loses power, three containers vanish, and nobody notices until users complain. This lesson answers what is Kubernetes, the tool built to prevent that night, what it gives you and when you do not need it.
The problem: many containers on many machines
On one machine, Docker and Compose are enough, and Docker can even restart a crashed container there if you give it a restart policy, a setting that says when to start it again. The trouble starts when you need more machines, for load or to survive a failure.
With ten containers on three servers, new questions appear. Which server has room for the next one? Who notices a dead server and starts its containers elsewhere? How do you update all ten a few at a time without an outage? And how do containers find each other when they move?
The diagram compares answering those by hand with describing the result once and letting software place and replace the containers. Notice that nobody had to act when node 2 was lost.
That software is an orchestrator: as What Is Docker? put it, a tool that runs containers across many machines and replaces them when one fails. Kubernetes is the one this course teaches.
What is Kubernetes?
Kubernetes is an open-source system for automating the deployment, scaling and management of containerized apps. It runs your containers across a cluster: a group of machines that Kubernetes manages as one pool. The name is Greek for helmsman or pilot, and people shorten it to K8s, because eight letters sit between the K and the s.
A cluster has two parts. Each node is one machine, physical or virtual, that runs your containers. The control plane is the set of programs that decide which node runs what and react when something fails; the next lesson opens it up.
Kubernetes wraps one or more containers in a pod, the smallest unit you can deploy, and a pod usually holds one main container. Until the pods lesson, think of a pod as one container that Kubernetes looks after.
In the diagram, the harbour master and the control plane both hold a plan, 6 ships or 6 pods. The replacement on dock 3 and node 3 exists only because the plan still says 6.
Kubernetes came from Google, which ran its own services in containers on an internal system called Borg. Google released Kubernetes as open source in 2014 and in 2015 gave it to the new Cloud Native Computing Foundation (CNCF), part of the Linux Foundation, which still hosts it.
The big idea: desired state
As in the Compose lesson, you describe what should exist in a declarative YAML file. Kubernetes stores what you write in the cluster as the desired state: what you want to be true. What is running right now is the actual state.
This file, web.yaml, asks for three copies of the nginx web server. A Deployment is the kind of object that keeps a set number of identical pods running; lesson 10 explains every line. For now, read kind, replicas: 3 (the number of copies) and image.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.27-alpine
You send the file to a cluster with kubectl, the command-line tool for Kubernetes. You will install it in lesson 17 and run a file like this in lesson 18; for now, just read along. The -f flag names the file:
kubectl apply -f web.yaml
Kubernetes replies with one line, straight away, before any container has started:
deployment.apps/web created
That only means the control plane's front door, the API server, saved the desired state. With no cluster to talk to, you get an error containing connection refused instead, usually for localhost:8080, kubectl's fallback address. Seconds later, kubectl get deployment web shows whether reality has caught up (your AGE will differ):
NAME READY UP-TO-DATE AVAILABLE AGE
web 3/3 3 3 40s
3/3 means three pods are ready of three wanted. A typo in the image name leaves it at 0/3; lesson 20 shows how to find out why.
The work happens after the reply. A controller is a program in the control plane that watches one kind of object and acts when actual and desired state differ. In the flowchart, a pod is deleted or its node dies, the count drops to two, and the controller asks for a new pod. A container that merely crashes is restarted in place on its node instead.
What Kubernetes gives you
Desired state plus controllers give you Kubernetes' main features, each covered later:
- Self-healing: crashed containers are restarted, and pods on a node that stops responding are replaced elsewhere, after a few minutes by default (lesson 15 adds health checks).
- Scaling: change the number of copies with one command, or let the Horizontal Pod Autoscaler follow the load (lesson 22).
- Rolling updates and rollbacks: a new version replaces old pods a few at a time, and one command goes back (lesson 19).
- Service discovery and load balancing: a Service gives changing pods one stable name and spreads requests across them (lesson 11).
- Configuration and secrets: settings and passwords live in ConfigMaps and Secrets, outside the image (lesson 13).
It also places pods on nodes with room for the CPU and memory they ask for, like a large ship sent to a dock with space.
What it does not do, and when you do not need it
Kubernetes runs images; it does not build them. You still write a Dockerfile (lesson 3), build the image and push it to a registry, often in an automated pipeline. Nor does it fix your app: a bug crashes the new copy just like the old one.
It does not remove the need to understand networking: when traffic does not reach a pod, you debug with the ports, DNS and localhost ideas from lesson 5. It also has no built-in database for your app and no long-term monitoring or log storage; you choose and run those.
You may not need it at all. One app on one server is well served by Compose, and a small team may do better on a platform that runs containers for them, such as a serverless service. Kubernetes costs effort: concepts to learn, YAML to maintain and a new minor version about three times a year. It pays off when many services on several machines must heal, scale and update on their own.
Check yourself
Your Deployment asks for replicas: 3, and a teammate deletes one of its pods by hand. What happens next, and why?
A new pod soon appears. Deleting a pod changes the actual state, not the desired state, so the controller sees two instead of three and starts a replacement. To keep two, change the file to replicas: 2 and apply it.
kubectl apply printed deployment.apps/web created. Is your app running yet?
Not necessarily. The reply only means the desired state was stored; controllers and nodes start the pods afterwards, so check kubectl get deployment web for 3/3.
A two-person team runs one web app and its database on one server, with no plans to grow. Should they start with Kubernetes?
Probably not. Kubernetes pays off when work spans many machines that must heal and scale on their own; on one server, Compose does the job with far less to learn and run.
Go deeper
- Setup Kubernetes cluster monitoring the easy way: Kubernetes brings no monitoring of its own; this post adds Prometheus and Grafana to a real cluster.
- NGINX ingress controller – Deep dive with AWS EKS: how outside traffic reaches pods on a managed cluster.