Kubernetes
Kubernetes (usually shortened to K8s) is an open-source system for running containers across a fleet of machines. You tell it what you want running ("five copies of this image, each with 1 CPU and 2 GB of memory, reachable at this name") and it works out where to put them, starts them, restarts them when they crash, and moves them when a machine dies.
That description packs in a few ideas worth separating:
- Container orchestration: Docker gives you a way to package and run one container on one machine. Kubernetes decides which of your hundreds of machines each container should run on and keeps it running there.
- Declarative: You don't issue commands like "start a container on node 7." You write down the state you want, and Kubernetes keeps working to make reality match it. This is the most important idea in Kubernetes, and almost everything else follows from it.
- Self-healing: Because Kubernetes keeps comparing what you asked for with what is running, a crashed process, a failed health check or a dead machine all get fixed the same way: by noticing the difference and closing it.
You won't be asked to design Kubernetes in most product interviews, and you rarely need to draw it. But it comes up constantly in infrastructure and platform rounds ("design a CI/CD system," "design a job scheduler," "design a container orchestrator"), and interviewers like to probe on it when you say "we'll deploy this on Kubernetes." So we'll cover how it works, what to say about it in an interview, and where it doesn't fit.
The Core Objects
Kubernetes is driven by a set of objects that you create through its API, almost always as YAML. There are dozens of them, but you only need a handful for an interview.
Pod: The smallest thing Kubernetes runs. A pod is one or more containers that share a network address and can share storage volumes. Usually it's just one container (your app), sometimes with a helper container next to it, called a sidecar (a log shipper or a service-mesh proxy). Each pod gets its own IP address. Pods are disposable. When one dies, it isn't repaired, it's replaced by a new pod with a new IP.
Deployment: Describes a set of identical, stateless pods: which image, how many replicas, and how to roll out a new version. You almost never create pods directly. You create a Deployment, and it keeps the right number of pods running.
Service: A stable name and virtual IP in front of a changing set of pods. Pods come and go, but orders-service always resolves to the same address, and Kubernetes load-balances requests across whichever pods are currently healthy behind it.
Node: A machine (VM or physical) that runs pods. A cluster is a set of nodes plus the control plane that manages them.
A minimal Deployment looks like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: orders
spec:
replicas: 5
selector:
matchLabels: { app: orders }
template:
metadata:
labels: { app: orders }
spec:
containers:
- name: orders
image: registry.example.com/orders:1.42.0
resources:
requests: { cpu: "500m", memory: "1Gi" }
limits: { memory: "1Gi" }
readinessProbe:
httpGet: { path: /healthz, port: 8080 }
Notice the labels. Kubernetes connects objects by label selectors, not by name. The Deployment manages every pod labelled app: orders, and a Service with the selector app: orders routes to the same pods. This loose coupling is what lets you swap pods in and out without updating anything else.
There are a few more objects you'll want to recognize:
- StatefulSet: like a Deployment, but each pod gets a stable identity (
db-0,db-1,db-2) and its own persistent disk that follows it if it's rescheduled. This is what you use for databases, Kafka brokers and anything else where replicas aren't interchangeable. - Job / CronJob: run a pod to completion once, or on a schedule.
- DaemonSet: run exactly one pod on every node, usually for agents like log collectors and monitoring.
- ConfigMap / Secret: configuration and credentials, mounted into pods as files or environment variables.
- Ingress / Gateway: HTTP routing from outside the cluster to Services, by hostname and path.