Kubernetes

You describe what you want running. The cluster keeps it that way — restarting, rescheduling and scaling, forever, without you in the loop.

The cluster Control plane · Workers · Pods that respawn

A bank runs 200 microservices on 80 servers. On Tuesday morning, one of the servers dies. Two of the services that were running on it go offline. Pagers go off across three teams.

The operations team logs in. They find a healthy server with spare capacity. They install Docker, copy the container images, copy the config, fight with the network, start the services, update the load balancer. Forty minutes later the site is back up.

By Wednesday lunchtime, the same thing has happened to a different server. The team is tired.

Kubernetes makes the operations team unnecessary for this story. The bank declares "I want three copies of each service running, somewhere in the cluster." When a server dies, Kubernetes notices, finds spare capacity, restarts the lost services, updates the network — in seconds — while the team is still asleep.

01What is Kubernetes, really?

Kubernetes (often shortened to K8s — eight letters between the K and the s) is an open-source container orchestrator. It takes a pile of machines and turns them into a single, programmable platform that runs your applications and keeps them running.

The simple version

Kubernetes is the operating system for a cluster of machines. You don’t care which machine your app runs on — you ask the cluster to run it, and the cluster chooses.

The technical version

Kubernetes is a system of controllers that read your desired state from an API and constantly drive the actual state of the cluster to match it. If reality drifts — a pod crashes, a node dies — the controllers fix it without a human.

The one-line version

"Compare what you asked for to what is running, and change the gap." Everything else — the YAML, the pods, the services — is plumbing around that loop.

02Why teams reach for Kubernetes

Kubernetes is not the simplest tool, and it’s overkill for a small static website. But once you have more than a handful of services, four benefits start to compound.

Benefit 01

Self-healing

A pod crashes — Kubernetes starts a new one. A node dies — the scheduler moves the lost pods to healthy nodes. The desired state is the agreement; everything else is the cluster’s job.

Benefit 02

Declarative everything

You write YAML that says what you want. You don’t write scripts that say how. Same file works in dev, staging and prod. Same file ten years from now.

Benefit 03

One platform, many languages

Go, Python, Java, Node, .NET, Rust — they all become "a container in a pod". One platform team supports them all, with the same monitoring, the same secrets, the same networking.

Benefit 04

Auto-scaling on every axis

More pods (HPA) when CPU is hot. Bigger pods (VPA) when needed. More nodes (Cluster Autoscaler or Karpenter) when pods can’t schedule. Scale-to-zero (KEDA) when nothing is happening.

03The two halves of a cluster

Every Kubernetes cluster has two kinds of machines: the control plane (the brain) and the worker nodes (the muscles). Knowing which component lives where helps you reason about failures and security.

Control plane — the brain

Decides and remembers

Runs on a small number of dedicated machines (in managed services like EKS, AKS, GKE you don’t see them).

  • kube-apiserver The only door into the cluster. Everything talks to it.
  • etcd The cluster’s database. Stores every object.
  • kube-scheduler Decides which node a new pod should land on.
  • kube-controller-manager Runs the reconcile loops.
  • cloud-controller-manager Talks to AWS / Azure / GCP for load balancers, disks, etc.
Workers — the muscles

Run the actual pods

Every "machine that runs your apps" is a worker node. You usually have many of them.

  • kubelet The agent on each node. Asks the API server "what should I run?", then runs it.
  • containerd / CRI-O The container runtime. Pulls images, starts containers.
  • kube-proxy Wires up the Service abstraction with iptables or IPVS.
  • CNI plugin Gives every pod an IP (Cilium, Calico, Flannel, …).

04The seven objects you must know

Kubernetes has hundreds of object types, but you can do 90% of the work knowing just seven. Master these and the rest are variations on a theme.

  • PodSmallest deployable unit. One or more containers that share an IP and storage. Almost never created directly — you create a Deployment.
  • DeploymentDeclarative wrapper for stateless apps. Maintains N pods, handles rolling updates and rollbacks via ReplicaSets.
  • StatefulSetFor stateful apps like databases. Each pod gets a stable network name and its own persistent volume.
  • DaemonSetRuns exactly one copy of a pod on every node. Log shippers, metric agents, CNI plugins.
  • ServiceA stable virtual IP and DNS name in front of pods that come and go. The "address" for a workload.
  • Ingress / GatewayExternal HTTP/HTTPS traffic into the cluster. Hostnames, paths, TLS termination.
  • ConfigMap / SecretConfiguration and credentials, injected as files or environment variables. Secret is Base64 by default (encryption is configured separately).

05A real Deployment + Service

Thirty lines that give you three replicas, a rolling update strategy, health checks, resource limits and a load-balanced address inside the cluster.

web.yamlYAML
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  selector:
    matchLabels: { app: web }
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels: { app: web }
    spec:
      containers:
        - name: web
          image: ghcr.io/you/web:1.4.2
          ports: [{ containerPort: 8080 }]
          resources:
            requests: { cpu: "100m", memory: "128Mi" }
            limits:   { cpu: "500m", memory: "512Mi" }
          readinessProbe:
            httpGet: { path: /healthz, port: 8080 }
            periodSeconds: 5
          livenessProbe:
            httpGet: { path: /healthz, port: 8080 }
            periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  selector: { app: web }
  ports: [{ port: 80, targetPort: 8080 }]
  type: ClusterIP

06What happens when a pod dies at 3 a.m.

This is the magic that makes Kubernetes worth its complexity. Walk through the loop once and you understand the whole system.

Detect

The kubelet on the affected node reports that a pod has crashed (or the whole node goes silent and is marked NotReady).

Compare

A controller sees "Deployment wants 3 replicas, 2 are running". The gap is one pod.

Schedule

The scheduler picks a node that has spare CPU/memory and matches the pod’s taints, tolerations and affinity rules.

Start

The kubelet on the chosen node pulls the image, starts the container, waits for the readiness probe to pass.

Route

Once the new pod is Ready, it’s added to the Service’s endpoints. Traffic resumes. Nobody noticed.

07Auto-scaling at three levels

Kubernetes scales pods, scales the size of pods, and scales the underlying cluster — all on autopilot, once you wire it up.

HPA — Horizontal Pod Autoscaler
Adds or removes pods when CPU, memory or a custom metric crosses a threshold. The default scaling answer.
VPA — Vertical Pod Autoscaler
Adjusts CPU and memory requests per pod over time. Useful for right-sizing, but pair carefully with HPA.
Cluster Autoscaler / Karpenter
Adds nodes when pods can’t be scheduled, removes them when nodes are underused. Karpenter is the modern, faster option on AWS.
KEDA
Event-driven autoscaler. Scale on queue depth, Kafka consumer lag, cron schedules, even scale to zero between events.

08Habits that keep your cluster boring

Kubernetes failures are rarely the cluster’s fault — they’re configuration details that got skipped. Make these defaults.

Anti-pattern
No resource limits. A bug causes one pod to leak memory; it starves every other pod on the node. Always set requests and limits, especially memory.
Anti-pattern
No readiness probe. A pod accepts traffic the instant it starts — before it has loaded config, opened DB connections, warmed caches. First users see errors. Add a real readiness probe.
Anti-pattern
Image tag :latest in production. The pod might come up with a different version than the one next to it. Always pin a tag or digest.
Anti-pattern
Storing secrets in ConfigMaps. They look the same but are treated very differently by RBAC, encryption-at-rest and audit. Use Secrets — or a real secret manager mounted via CSI.
Healthy
GitOps from day one. Manifests live in Git. Argo CD or Flux reconciles them into the cluster. No kubectl apply from a laptop.

09Putting it together

Take-aways

1. Kubernetes is a reconcile loop: you declare desired state, the cluster makes reality match it — and keeps it matching.

2. Two halves: the control plane (brain) and the worker nodes (muscles). Seven objects (Pod, Deployment, StatefulSet, DaemonSet, Service, Ingress, ConfigMap/Secret) cover most of the work.

3. Self-heal, declarative everything, one platform for every language, and auto-scaling on every axis — the four reasons it’s worth the complexity.

4. Resource limits, readiness probes, pinned images, Secrets (not ConfigMaps), GitOps. Five defaults that keep clusters boring.

Next chapter: now your services are running. How do you know they are healthy — not just alive? That is observability.