What is Kubernetes, and why is it used for container orchestration?
Kubernetes is an open-source platform that runs containers across a cluster of machines and keeps them in the state you declare. You describe the desired state (for example “three replicas of this image, reachable on port 80”), and Kubernetes controllers keep comparing it with the actual state and fix any difference: they restart crashed containers, replace pods on failed nodes, roll out new versions and route traffic only to healthy instances. It is used because running more than a handful of containers by hand, with scripts, does not scale and does not heal itself.
Read full answerHide full answer
Applies toKubernetes 1.29+ on managed services (EKS, GKE, AKS) or self-hosted clusters
The Problem It Solves
Docker runs a container on one machine. A production service needs more:
-
Placing containers on machines with enough CPU and memory.
-
Restarting them when they crash and moving them when a machine dies.
-
Giving a changing set of containers one stable address and spreading traffic across them.
-
Rolling out a new version without downtime, and rolling back when it misbehaves.
-
Scaling out under load and back in when it drops.
-
Injecting configuration and credentials without rebuilding images.
Kubernetes handles each of these with a built-in object instead of custom tooling.
The Declarative, Reconcile-Loop Model
-
You submit a manifest (YAML) to the API server, which stores it in etcd.
-
A controller watches that object type and compares desired with actual state.
-
When they differ, it acts: a Deployment controller creates pods, the scheduler picks a node for each, and the kubelet on that node starts the containers.
-
The loop never stops. If a node dies, the pod count drops below the desired three, and a replacement is created elsewhere.
This is why you change a cluster by editing manifests, not by issuing step-by-step commands.
apiVersion: apps/v1
kind: Deployment
metadata:
name: url-shortener
spec:
replicas: 3
selector:
matchLabels:
app: url-shortener
template:
metadata:
labels:
app: url-shortener
spec:
containers:
- name: api
image: registry.example.com/url-shortener:1.4.2
ports:
- containerPort: 8080
resources:
requests:
cpu: 250m
memory: 256Mi
limits:
memory: 512Mi
readinessProbe:
httpGet:
path: /healthz
port: 8080
kubectl apply -f deployment.yaml kubectl get pods -l app=url-shortener kubectl rollout status deployment/url-shortener
Core Building Blocks
| Object | What it gives you |
|---|---|
| Pod | One or more containers sharing a network namespace and volumes |
| Deployment / ReplicaSet | N identical, replaceable pods with rolling updates |
| StatefulSet | Pods with stable names and their own storage |
| Service | A stable virtual IP and DNS name over a changing set of pods |
| Ingress / Gateway API | HTTP routing from outside the cluster |
| ConfigMap / Secret | Configuration and credentials kept outside the image |
| HorizontalPodAutoscaler | Replica count driven by CPU, memory or custom metrics |
Trade-offs
| Benefit | Cost |
|---|---|
| Self-healing and rolling updates | A control plane to run, upgrade and secure (or pay a provider for) |
| Portable across clouds and on-premises | Many concepts to learn: networking, RBAC, storage classes |
| Consistent deployment model for every team | YAML sprawl; usually needs Helm or Kustomize |
| Efficient bin-packing of workloads | Debugging spans pods, nodes, DNS and the network plugin |
When Not to Use It
-
A single small app or a team without operations experience: a PaaS, a managed container service or a couple of VMs behind a load balancer is cheaper to run.
-
Purely serverless, event-driven workloads that already fit a functions platform.
-
When nobody will own upgrades: Kubernetes minor versions are supported for roughly 14 months, so clusters need regular upgrades.
Interview Tip
Interviewers look for the reconcile loop in your answer, not a list of features. Say “desired state versus actual state, continuously reconciled by controllers”, and distinguish Docker (builds images and runs containers on one host) from Kubernetes (schedules and manages containers across many hosts). A common mistake is to call Kubernetes a container runtime; it delegates running containers to a runtime such as containerd through the CRI.