Skip to content

Lesson 18 of 24Kubernetes

From Containers to Kubernetes

Know what orchestration solves, read a basic Kubernetes Deployment and Service, and judge when you do not need it.

20 min read0/7 questions

Docker runs containers on one machine. Real products run dozens of containers across many machines, and something has to decide where each one goes, replace the ones that die, and roll out new versions without downtime. That something is an orchestrator, and Kubernetes is the one you will see on job descriptions. Knowing its core ideas, and when it is overkill, is a common senior-leaning interview topic.

What an orchestrator does

Imagine your API runs as 6 containers on 3 servers. On Docker alone, you would be answering these questions by hand, at 3 a.m.:

  • Scheduling. Which server has room for another container with 512 MB of memory?
  • Self-healing. A container crashed, or a whole server died. Who starts replacements, and where?
  • Scaling. Traffic tripled. Who adds containers, and who removes them later?
  • Rolling updates. How do you replace v1 with v2 one container at a time, and roll back if v2 is broken?
  • Service discovery and load balancing. Containers come and go with new IP addresses. How does traffic find the healthy ones?
  • Config and secrets. How does each container get its settings without baking them into the image?

An orchestrator automates all of this. Kubernetes (often written K8s) is the dominant open-source one. It grew out of Google's internal systems and was released in 2014; it is now run by the Cloud Native Computing Foundation.

Desired state and the reconcile loop

The central idea: you do not tell Kubernetes what to do, you tell it what you want. "I want 3 copies of api:sha-7f3c2a1 running." Controllers inside Kubernetes then loop forever, comparing the desired state with the actual state and acting on the difference. This is called reconciliation.

Pythonreconcile.py
desired = {"image": "api:sha-7f3c2a1", "replicas": 3}pods = ["api-a", "api-b", "api-c"]counter = iter("defghij") def reconcile() -> None: while len(pods) < desired["replicas"]: name = f"api-{next(counter)}" pods.append(name) print(" created", name) while len(pods) > desired["replicas"]: print(" deleted", pods.pop()) print("node-b dies, taking api-b with it")pods.remove("api-b")reconcile()print("traffic spike: scale to 5")desired["replicas"] = 5reconcile()print("running:", pods)
Output
Press Run (⌘ Enter) to see what happens.
Predict the outputPython

What does this print?

desired = 2
pods = ["a", "b", "c", "d"]

def reconcile():
  while len(pods) < desired:
      pods.append("new")
  while len(pods) > desired:
      pods.pop()

pods.remove("a")
reconcile()
print(pods)
Need a nudge? Hints walk you through it.

The core objects

Kubernetes has many object types, but a handful cover most apps.

ObjectWhat it is
ClusterThe whole system: a control plane (API server, scheduler, controllers, etcd database) plus worker machines.
NodeOne worker machine (usually a VM) that runs containers.
PodThe smallest unit Kubernetes runs: one container (sometimes a few tightly coupled ones) with its own IP. Pods are disposable.
DeploymentDesired state for a set of identical pods: which image, how many replicas, how to roll out updates.
ServiceA stable name and virtual IP that load-balances to whichever pods match a label. Pods change; the Service does not.
IngressHTTP routing from outside the cluster to Services, by host and path. (The newer Gateway API does the same job with more features.)
ConfigMapNon-secret configuration injected as env vars or files.
SecretSensitive values (passwords, keys) injected the same way, with tighter access control.
A request through a Kubernetes cluster
Kubernetes clusterUsersUsersIngress: api.shop.comIngressapi.shop.comService: api:80Serviceapi:80Pod api: node-aPod apinode-aPod api: node-bPod apinode-bPod api: node-cPod apinode-cControl plane: API serverControl planeAPI serverDeployment: replicas: 3Deploymentreplicas: 3ConfigMap: LOG_LEVELConfigMapLOG_LEVELSecret: DB_PASSWORDSecretDB_PASSWORDHTTPSroutereconcilemanagesenvenv

A request for api.shop.com enters through the Ingress, which routes it to the api Service.

1/5
Match the pairs0/5 matched

Match the need to the Kubernetes object.

Choose an item, then its match on the other side.

A minimal Deployment and Service

Kubernetes objects are written as YAML and sent to the API server with kubectl apply. This is the API from the previous lessons, running as 3 replicas.

k8s/api.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
spec:
  replicas: 3
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          image: ghcr.io/acme/api:sha-7f3c2a1
          ports:
            - containerPort: 8000
          envFrom:
            - configMapRef: { name: api-config }
            - secretRef: { name: api-secrets }
          resources:
            requests: { cpu: 250m, memory: 256Mi }
            limits: { memory: 512Mi }
          readinessProbe:
            httpGet: { path: /health, port: 8000 }
---
apiVersion: v1
kind: Service
metadata:
  name: api
spec:
  selector:
    app: api
  ports:
    - port: 80
      targetPort: 8000

Read the highlighted lines as a story. The Deployment wants 3 replicas of pods labelled app: api, built from a SHA-tagged image (from your CI in Docker in Production). The Service selects pods by the same label and forwards its port 80 to the container's port 8000. Everything you learned still applies: the app listens on 0.0.0.0:8000, logs to stdout, handles SIGTERM, and exposes /health for the readiness probe, which keeps traffic away from a pod until it is ready.

kubectl apply -f k8s/api.yamlkubectl get pods                       # 3 pods, Runningkubectl logs -f deploy/api             # logs from a pod of the deploymentkubectl set image deploy/api api=ghcr.io/acme/api:sha-9b1e004   # roll out v2kubectl rollout status deploy/api      # watch the rolling updatekubectl rollout undo deploy/api        # roll backkubectl scale deploy/api --replicas=6
Quick check
Why do other apps call the API through the api Service instead of a pod's IP address?
Need a nudge? A hint rules out a wrong answer.

Rolling updates

When you change the image, the Deployment replaces pods gradually. With the default settings it starts a new pod, waits until its readiness probe passes, then terminates an old one (with SIGTERM and a 30 second grace period), and repeats.

Pythonrolling_update.py
pods = ["v1", "v1", "v1"]step = 0while "v1" in pods: step += 1 pods.append("v2") # surge: start one new pod print(f"step {step}: start v2, wait for ready -> {pods}") pods.remove("v1") # then retire one old pod print(f"step {step}: SIGTERM one v1 -> {pods}")
Output
Press Run (⌘ Enter) to see what happens.

At every moment at least 3 pods are serving. If the new pods never become ready, the rollout stalls instead of taking the site down, and kubectl rollout undo brings v1 back.

Quick check
You deploy v2, but its pods crash on start-up. With a readiness probe configured, what do users experience?
Need a nudge? A hint rules out a wrong answer.

Ingress, Gateway API and a retired controller

The Ingress in the diagram above is still everywhere, so you need to read it. Two facts about it changed recently, and they are easy to mix up.

  • The Ingress API is feature-frozen, not removed. kind: Ingress still works on current clusters and is not going away soon. It simply gets no new features. Anything beyond host and path routing (header matching, traffic splitting, timeouts) was always done with controller-specific annotations, which is why Ingress YAML from one controller rarely works on another.
  • The ingress-nginx controller was retired in March 2026. This is one popular implementation of Ingress, maintained by the Kubernetes project. It no longer gets releases or security fixes. Existing installs keep running, but an internet-facing proxy without patches is a risk, so teams are migrating off it. F5's NGINX Ingress Controller is a separate product and is not affected.

The replacement for new work is the Gateway API. It splits the job across objects owned by different people: a GatewayClass (which implementation, picked by the platform team), a Gateway (the listener, ports and TLS, also platform-owned), and an HTTPRoute (which paths go to which Service, owned by the app team). Features that needed annotations, such as sending 10 percent of traffic to a canary, are part of the standard. Services, Gateway API and Network Policies covers it in detail, including the migration.

Quick check
A colleague says 'Ingress was retired in 2026, so our Ingress objects will stop working on the next cluster upgrade.' What is accurate?
Need a nudge? A hint rules out a wrong answer.

Nodes do not run Docker

You build with Docker, and a Kubernetes node runs your image, but the node almost certainly has no Docker engine on it. Kubernetes talks to a container runtime through an interface called the CRI. Docker never implemented it, so Kubernetes used a shim, and that shim was removed in Kubernetes 1.24. Nodes today run containerd or CRI-O.

Nothing about your images changes. Docker builds images in the OCI format, which every runtime reads, so the same ghcr.io/acme/api:sha-7f3c2a1 runs on your laptop and on the cluster. What does change is debugging on a node: docker ps is not there. Tools such as crictl talk to the runtime directly, though most of the time kubectl logs, kubectl exec and kubectl debug from your own machine are the better route. If you hear "Kubernetes dropped Docker support", the precise answer is "it dropped the Docker engine as a runtime; Docker-built images work unchanged".

After this lesson

This lesson gives you the vocabulary. The Kubernetes unit takes each idea to the level a team expects from someone who deploys to a cluster.

The Kubernetes unit
  1. Next

    Kubernetes Workloads and kubectl

    Pods up close, choosing between Deployment, StatefulSet, DaemonSet and Job, how a rollout really proceeds, and debugging Pending, CrashLoopBackOff and OOMKilled.

  2. Then

    Services, Gateway API and Network Policies

    What a Service is on the wire, cluster DNS, getting traffic in with Gateway API and TLS, and default-deny network policies.

  3. Then

    Config, Secrets, Probes and Autoscaling

    ConfigMaps and Secrets, the three probes, requests and limits, graceful shutdown, autoscaling and RBAC.

  4. Last

    Helm, Kustomize and GitOps Deploys

    Packaging one app for several environments and letting Argo CD or Flux deploy every change from git.

Managed Kubernetes and simpler options

Running the control plane yourself is hard, so most teams rent it. And many teams do not need Kubernetes at all: several platforms take an image and handle scheduling, scaling, and rollouts with far less to learn.

OptionYou manageGood fit
EKS (AWS), GKE (Google), AKS (Azure)Worker nodes (or use GKE Autopilot / EKS Auto Mode), all K8s objectsMany services, platform team, need the K8s ecosystem
ECS on Fargate (AWS)Task definitions and services; no serversAWS shops wanting containers without K8s
Cloud Run (Google), Azure Container AppsAlmost nothing: give it an image and a portHTTP APIs, scale to zero, small teams
Fly.io, Render, RailwayAn app config fileSide projects, startups, global deploys with little ops
Compose on one VMThe VM, updates, backupsSmall apps with modest traffic and a tight budget
Quick check
A two-person startup has one FastAPI service, one Postgres database, and a React frontend, with a few thousand users. What is the most sensible way to run it?
Need a nudge? A hint rules out a wrong answer.
Put it in order4 steps

Order the hops of a request from the internet to your code in Kubernetes.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.
Key terms
orchestrator
Software that schedules, heals, scales, and updates containers across many machines.
pod
The smallest unit Kubernetes runs: one or a few containers sharing an IP. Disposable.
Deployment
Desired state for identical pods: image, replica count, and rolling update strategy.
Service
A stable name and virtual IP that load-balances to the pods matching a label selector.
reconciliation
Controllers repeatedly comparing desired and actual state and acting to close the gap.
readiness probe
A health check that decides whether a pod receives traffic, used to make rollouts safe.
Gateway API
The successor to Ingress: GatewayClass, Gateway and HTTPRoute objects that split routing between platform and app teams.
container runtime (CRI)
The software a node uses to run containers, such as containerd or CRI-O, reached through the Container Runtime Interface.