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.
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.
Press Run (⌘ Enter) to see what happens.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)The core objects
Kubernetes has many object types, but a handful cover most apps.
| Object | What it is |
|---|---|
| Cluster | The whole system: a control plane (API server, scheduler, controllers, etcd database) plus worker machines. |
| Node | One worker machine (usually a VM) that runs containers. |
| Pod | The smallest unit Kubernetes runs: one container (sometimes a few tightly coupled ones) with its own IP. Pods are disposable. |
| Deployment | Desired state for a set of identical pods: which image, how many replicas, how to roll out updates. |
| Service | A stable name and virtual IP that load-balances to whichever pods match a label. Pods change; the Service does not. |
| Ingress | HTTP routing from outside the cluster to Services, by host and path. (The newer Gateway API does the same job with more features.) |
| ConfigMap | Non-secret configuration injected as env vars or files. |
| Secret | Sensitive values (passwords, keys) injected the same way, with tighter access control. |
A request for api.shop.com enters through the Ingress, which routes it to the api Service.
Match the need to the Kubernetes object.
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.
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: 8000Read 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=6api Service instead of a pod's IP address?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.
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.
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: Ingressstill 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.
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.
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.
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.
Then
Config, Secrets, Probes and Autoscaling
ConfigMaps and Secrets, the three probes, requests and limits, graceful shutdown, autoscaling and RBAC.
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.
| Option | You manage | Good fit |
|---|---|---|
| EKS (AWS), GKE (Google), AKS (Azure) | Worker nodes (or use GKE Autopilot / EKS Auto Mode), all K8s objects | Many services, platform team, need the K8s ecosystem |
| ECS on Fargate (AWS) | Task definitions and services; no servers | AWS shops wanting containers without K8s |
| Cloud Run (Google), Azure Container Apps | Almost nothing: give it an image and a port | HTTP APIs, scale to zero, small teams |
| Fly.io, Render, Railway | An app config file | Side projects, startups, global deploys with little ops |
| Compose on one VM | The VM, updates, backups | Small apps with modest traffic and a tight budget |
Order the hops of a request from the internet to your code in Kubernetes.
- Tap the steps below in the right order.
- 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.