Knowing what problem it solves tells you when it is worth its complexity and when Docker Compose is enough.
Docker runs containers on one machine. In production you need more: run ten copies of a service across several servers, restart them when they crash, move them when a server dies, roll out a new version without downtime, and give them a stable network address. Kubernetes (k8s) is the system that does this.
The central idea is declarative desired state. You don't say "start three containers"; you submit an object that says "there should be three replicas of this image". Controllers inside Kubernetes constantly compare the actual state with the desired state and act to close the gap. If a node dies, the replicas on it vanish, the controller notices only one is running and creates two more elsewhere.
Everything is an object in the Kubernetes API: Pods, Deployments, Services, ConfigMaps and so on. You create and change them with kubectl or any API client, usually from YAML files kept in git.
When it is worth it:
- several services, several machines, or a need for zero-downtime deploys and self-healing,
- a team that wants one standard platform (EKS, GKE, AKS or self-hosted).
For a single small app on one server, Docker Compose is far simpler.
Example
# Imperative: you do each step and must react to failures yourself
docker run -d --name web nginx:1.27
# Declarative: you state the goal; Kubernetes keeps it true
kubectl create deployment web --image=nginx:1.27 --replicas=3
kubectl get pods
# NAME READY STATUS RESTARTS AGE
# web-6d4cf56db6-2xk8p 1/1 Running 0 10s
# web-6d4cf56db6-7qv9z 1/1 Running 0 10s
# web-6d4cf56db6-mm5rt 1/1 Running 0 10s
kubectl delete pod web-6d4cf56db6-2xk8p
kubectl get pods # a replacement pod appears within secondsRemember
- You declare desired state; controllers reconcile reality towards it
- Everything is an API object, usually written as YAML
- Worth it for multi-service, multi-node, self-healing needs; overkill for one small app
Watch out for
- Adopting Kubernetes for a single small service where Compose on one VM would do.