What is Kubernetes, and why do we need it?
In one line: Kubernetes (K8s) is an open-source platform that runs and manages containers across a cluster of machines — it handles deployment, scaling, self-healing, networking and rolling updates automatically.
Why we need it: running one container with docker run is easy. Running 200 containers across 20 servers is not: which server has space? What if a container crashes at 3 a.m.? How do containers find each other? How do you update without downtime? Kubernetes answers all of these.
What Kubernetes does:
- Scheduling — decides which node each container (pod) runs on, based on available resources.
- Self-healing — restarts crashed containers, replaces pods on failed nodes, and only sends traffic to healthy pods.
- Scaling — scale manually (
kubectl scale) or automatically (Horizontal Pod Autoscaler). - Service discovery and load balancing — gives pods stable names (Services + DNS) and spreads traffic.
- Rolling updates and rollbacks — update with zero downtime; undo with one command.
- Configuration and secrets — ConfigMaps and Secrets injected into pods.
- Storage — attaches persistent volumes (EBS, Azure Disk) to pods.
- Declarative desired state — you write YAML describing what you want; Kubernetes keeps reality matching it.
Simple example:
apiVersion: apps/v1
kind: Deployment
metadata: { name: orders }
spec:
replicas: 3
selector: { matchLabels: { app: orders } }
template:
metadata: { labels: { app: orders } }
spec:
containers:
- name: orders
image: myrepo/orders:1.4.2
ports: [{ containerPort: 8080 }]
Kubernetes keeps 3 copies running at all times. Delete one pod and a new one appears.
Managed options: EKS (AWS), AKS (Azure), GKE (Google), OpenShift (Red Hat).
Tip for interviews: mention the "desired state" idea and self-healing — they're the core of how Kubernetes works.