Catalog My learning Blog
Docker and Kubernetes Tutorial: Containers to Production · Phase 3 · Lesson 15 · 3 min read

Why Kubernetes? From Docker to Orchestration

On this page
  1. When a deploy script turns into an orchestrator
  2. Problems that appear with many hosts
  3. Declarative vs imperative: how Kubernetes reconciles state
  4. What Kubernetes costs, and when not to use it
  5. What comes next in the course
  6. Check yourself

When a deploy script turns into an orchestrator

A team runs three replicas of its API on three servers with an SSH script that loops over hosts and runs docker run. Then:

  • One server dies at night. Its replica is gone until someone notices in the morning.
  • A deploy fails halfway: two servers run the new version, one the old.
  • Traffic doubles. Someone edits the script to start a fourth replica, on whichever server seems least busy.
  • The load balancer config lists container IPs by hand, and they change on every restart.

Each problem is solvable with more script. Together they're a distributed system you're writing by accident. Orchestrators exist so you don't.

Problems that appear with many hosts

ProblemQuestion it raises
SchedulingWhich host has room for this container's CPU and memory?
Self-healingA container or host died; who replaces it, and where?
ScalingHow do we add replicas when load rises, and remove them later?
RolloutsHow do we replace versions gradually and undo a bad one?
Service discoveryHow do clients find replicas whose IPs keep changing?
ConfigurationHow do containers get config and secrets on any host?
StorageHow does data follow a container that moves to another host?

Declarative vs imperative: how Kubernetes reconciles state

The script is imperative: a list of steps ("run this here, then that there"). If any step fails or reality changes later, the script doesn't know.

Kubernetes is declarative: you describe the desired state, and controllers keep reality matching it, continuously:

YAML
apiVersion: apps/v1
kind: Deployment
metadata:
  name: orders-api
spec:
  replicas: 3
  selector:
    matchLabels: { app: orders-api }
  template:
    metadata:
      labels: { app: orders-api }
    spec:
      containers:
        - name: api
          image: ghcr.io/myorg/orders-api:1.4.2
          ports: [{ containerPort: 8080 }]

"There should be three replicas of this image." If a node dies and takes one replica with it, a controller notices the count is two and starts another elsewhere. Nobody runs a script. This loop, observe, compare with desired state, act, is called reconciliation, and it's how every part of Kubernetes works.

An imperative script runs steps once; Kubernetes controllers continuously compare desired state with reality and correct the difference.
An imperative script runs steps once; Kubernetes controllers continuously compare desired state with reality and correct the difference.

What Kubernetes costs, and when not to use it

Kubernetes is a large system with many concepts, its own security model, networking and upgrade cycle. Running your own control plane is a serious job; most teams use a managed service (AKS, EKS, GKE) and still spend real effort on it.

For a few services on one or two hosts, Docker Compose or a managed container platform (Azure Container Apps, AWS ECS or App Runner, Google Cloud Run) may serve you better. Kubernetes pays off with many services, several teams, frequent deploys and a need for consistent tooling across them.

What comes next in the course

Day 16 opens up the cluster: the control plane and the nodes. Days 17 to 24 cover the objects you'll use daily: Pods, Deployments, Services, configuration, storage, namespaces, Ingress and autoscaling.

Check yourself

Imperative executes a sequence of steps once; declarative states the desired end result, and the system keeps working toward it even as things change.

The ReplicaSet controller notices that only two of the desired three Pods are running and creates a replacement, and the scheduler places it on a healthy node with enough capacity. No one has to intervene, because Kubernetes keeps reconciling the actual state toward the declared state.

For a handful of services on a single host or a small team, where Compose or a managed container platform gives most of the benefit with far less to operate.

Placing containers on hosts with free capacity, restarting them when they or their host fail, rolling out new versions without downtime, letting services find each other as containers move, and distributing configuration and secrets. Doing all that with scripts quickly becomes a home-grown orchestrator.

You declare the desired state in manifests, and controllers continuously compare it with the actual state and act to close the gap. When something drifts, such as a crashed Pod, the controller corrects it without a new command from you.