04

Why Kubernetes Is Used

Video: Day 4/40 — Why Kubernetes Is Used — Simply Explained • https://www.youtube.com/watch?v=lXs1VCWqIH4 • Duration: ~8 min

Key terms

TermMeaning
OrchestratorSystem that schedules, scales, and heals containers across nodes
PodSmallest deployable unit (one or more containers)
Desired stateThe state you declare in manifests
Actual stateWhat is really running in the cluster
ReconciliationControllers driving actual state toward desired state
Self-healingAutomatic replacement of failed pods
ScalingAdding or removing replicas to match load

Problem & solution

Docker runs containers on a single host with no built-in self-healing, scaling, or zero-downtime updates. Running many containers across many machines by hand doesn't scale and can't survive a failed container or a dead host.

Solution: Use an orchestrator that schedules, self-heals, scales, and load-balances containers across many machines automatically, instead of doing it by hand.

The analogy

Picture a busy harbor where a single dock-hand tries to park every arriving ship by hand: he cannot watch them all, tug in a replacement for one that sinks, or open extra berths when traffic spikes. A port authority instead orchestrates thousands of ships automatically, assigning berths, replacing lost vessels, and adding capacity on demand. Plain Docker on a single host is that lone dock-hand, while Kubernetes is the port authority that schedules, heals, and scales your containers across many machines.

Where this fits in the cluster

The same cluster entities appear in every day's notes; the diagram below shows where this day's topic fits.

Graph legend — each node maps to a real cluster component running the nginx example:

Graph nodeMaps toWhat it does
api-serverkube-apiserverThe single entry point for all cluster operations
etcdthe etcd datastoreStores desired/actual state (your nginx replica count)
schedulerkube-schedulerPicks a node for each new nginx pod
controller-managerkube-controller-managerSelf-heals and scales the nginx Deployment
Pod - nginx replicaone nginx podA single running copy of the app
container - nginx:1.27the nginx:1.27 containerThe actual web server process

The problem with plain Docker at scale

Docker runs containers on one host. In production you need many containers across many machines, with self-healing, scaling, and zero-downtime updates. Doing this by hand does not scale.

What breaks without an orchestrator (ASCII)

On a single Docker host there is nobody to restart crashed containers, scale on demand, or survive a dead host.

Graph legend — each node maps to a failure plain Docker cannot handle:

Graph nodeMaps toWhat it does
nginx #1..#3three docker run nginx containers on one hostAll eggs in one basket, no controller watching them
nginx crashes - who restartsa dead containerNobody restarts it; the replica is simply lost
Host dies - all nginx gonethe single host failingEvery container vanishes with no failover
Traffic spike - manual scalingrising loadYou must docker run more by hand, with no autoscaling

What Kubernetes gives you

Kubernetes adds the production-grade capabilities that plain Docker lacks.

Graph legend — each node maps to a capability applied to the nginx Deployment:

Graph nodeMaps toWhat it does
Self-healthe ReplicaSet controllerRecreates any crashed nginx pod to keep the count
Auto-scalea HorizontalPodAutoscalerAdds/removes nginx replicas as CPU load changes
Rolling update / rollbackkubectl set image / rollout undoSwaps nginx:1.271.28 with no downtime, revertible
Load balance traffica Service + kube-proxySpreads requests across all nginx pods
  • Self-healing: restarts/replaces failed containers & nodes.
  • Horizontal scaling: add/remove replicas on demand.
  • Service discovery + load balancing: stable names, spread traffic.
  • Automated rollouts/rollbacks: ship safely, revert fast.
  • Config & secret management: decouple config from images.
  • Storage orchestration: attach volumes automatically.

Desired vs actual state (the core idea)

Kubernetes runs a control loop that constantly compares what you asked for against what is actually running, and fixes the gap.

Graph legend — each node maps to the reconcile loop for replicas: 3 of nginx:

Graph nodeMaps toWhat it does
You declare - replicas: 3 of nginxDeployment.spec.replicas: 3Your declared desired state
K8s control loopthe controller-managerContinuously compares actual pods vs desired
Create 1 more nginx podactual 2 < desired 3Scales up to reach the target
Delete 1 nginx podactual 4 > desired 3Scales down to the target
Recreate nginx poda crashed podReplaces it so the count stays at 3

You describe the end state; Kubernetes continuously works to make reality match it. This is "declarative" management.

When do you NOT need Kubernetes?

Kubernetes is powerful but carries real operational overhead, so it is not always the right choice. The cases below are situations where a simpler setup beats running a full cluster.

  • A single small app / hobby project -> Docker or a PaaS is simpler.
  • K8s adds real operational complexity; use it when scale/resilience demands it.

End-to-end flow

The control loop that keeps reality matching your declared state, healing and scaling automatically.

Graph legend — each node maps to the desired-state loop for the nginx Deployment:

Graph nodeMaps toWhat it does
You declare replicas: 3 of nginxDeployment.spec.replicasThe desired state you submit
API serverkube-apiserverAccepts and persists the request
Controller observes statekube-controller-managerWatches actual pod count
actual equals desired (3)the reconcile checkDecides whether action is needed
Create or delete nginx podsscale up/down actionDrives actual toward 3 replicas
Cluster reconciledsteady stateActual matches desired, loop idles

Key takeaways

  • Kubernetes = container orchestrator for many hosts.
  • It enforces a desired state via continuous control loops.
  • Core wins: self-healing, scaling, rollouts, service discovery.

Checklist

  • [ ] Can explain self-healing and desired-state in one sentence each
  • [ ] Understand why single-host Docker is not enough at scale