Why Kubernetes?
- Docker & Kubernetes course
- Intermediate
- Lesson 2/82
- 4 min
Learn the advantages Kubernetes provides.
Why Kubernetes?
On a single server, Compose is enough. As the application grows, these questions come up and Kubernetes answers all of them out of the box:
- Self-healing: the workload on a crashed container or server is restarted elsewhere.
- Scaling: the replica count changes by hand or automatically with load.
- Zero-downtime updates: a new version rolls out gradually and is rolled back if there's a problem.
- Service discovery and load balancing: replicas are gathered behind a single address.
kubectl scale deployment web --replicas=10Seeing self-healing
If you delete a deployment's pod by hand, the deployment immediately creates a new one to keep the desired replica count. -w (watch) follows the changes live:
$ kubectl delete pod web-7c5b9f6d8-abcde
pod "web-7c5b9f6d8-abcde" deleted
$ kubectl get pods -w
web-7c5b9f6d8-pqrst 0/1 ContainerCreating 0 1s
web-7c5b9f6d8-pqrst 1/1 Running 0 3sPractice Scale and watch
Write two commands: scale the web deployment to 5 replicas; then watch the pods live.
Starter code
# buraya yazSample solution
kubectl scale deployment web --replicas=5
kubectl get pods -wExpected output
deployment.apps/web scaled NAME READY STATUS RESTARTS AGE web-7c5b9f6d8-uvwxy 0/1 ContainerCreating 0 1s web-7c5b9f6d8-uvwxy 1/1 Running 0 3s
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 When can Kubernetes be unnecessary complexity?
- For a small application running on one server Correct answer
- For hundreds of microservices
- For multi-region deployment
- When autoscaling is needed
Explanation: Kubernetes has an operational cost; without the need, Compose is simpler.
2 Scale the deployment to 10 replicas.
kubectl ____ deployment web --replicas=10
kubectl scale deployment web --replicas=10
Explanation: scale changes the replica count.
3 Match the features.
| Term | Meaning |
|---|---|
self-healing |
Restarts what crashed |
scaling |
Changes the replica count |
rolling update |
Zero-downtime update |
service discovery |
Replicas behind one address |