Docker is about packaging apps into containers. Kubernetes is about managing those containers at scale. They're complementary, not competitors.
What is Kubernetes
Understand why Kubernetes exists, what problems it solves, and how it differs from Docker.
🧒 Simple Explanation (ELI5)
Imagine you run a restaurant. Docker is like a food truck — it packages everything needed to cook a single dish (your app + dependencies) into one portable container. But what happens when you have 100 food trucks across a city? Who decides which truck goes where? Who replaces a broken-down truck? Who handles the dinner rush?
Kubernetes is the fleet manager. It decides where each truck goes, replaces broken ones automatically, adds more trucks when demand spikes, and makes sure customers always get their food. You tell Kubernetes "I need 5 trucks running the pizza app" and it handles everything else.
🤔 Why Do We Need Kubernetes?
Without Kubernetes, running containers in production means you have to manually:
- Start and stop containers across multiple servers
- Restart crashed containers
- Distribute traffic across healthy containers
- Scale up when traffic increases, scale down when it drops
- Roll out new versions without downtime
- Handle secrets, configuration, and storage
Kubernetes automates all of this. It's the industry standard for container orchestration — used by Google, Microsoft, Amazon, and virtually every major tech company.
🔧 Technical Explanation
Kubernetes (often abbreviated K8s) is an open-source container orchestration platform originally designed by Google, now maintained by the Cloud Native Computing Foundation (CNCF).
Core Concepts
- Cluster: A set of machines (nodes) that run your containerized applications
- Control Plane: The brain — makes scheduling decisions, detects failures, responds to events
- Worker Nodes: The machines that actually run your application containers
- Desired State: You declare what you want (e.g., "3 replicas of app v2"), Kubernetes ensures reality matches
- Declarative Model: You write YAML manifests describing the desired state; Kubernetes reconciles continuously
What Kubernetes Does
| Capability | Description |
|---|---|
| Self-healing | Restarts failed containers, replaces unresponsive nodes |
| Horizontal scaling | Adds or removes container instances based on load |
| Service discovery | Built-in DNS and load balancing for services |
| Rolling updates | Zero-downtime deployments with rollback capability |
| Secret management | Stores and injects sensitive data securely |
| Storage orchestration | Mounts persistent volumes from cloud or local storage |
📊 Visual: Docker vs Kubernetes
⌨️ Hands-on: Your First Kubernetes Commands
If you have a cluster running (minikube, kind, or cloud), try these:
# Check cluster info kubectl cluster-info # See all nodes in the cluster kubectl get nodes # View all namespaces kubectl get namespaces # Run a simple pod kubectl run hello --image=nginx --port=80 # Check the pod status kubectl get pods # View pod details kubectl describe pod hello # Delete the test pod kubectl delete pod hello
Don't have a cluster yet? Install minikube or kind locally. For cloud, Azure AKS gives a free tier to experiment.
🐛 Debugging Scenario
Scenario: "Why not just use Docker Compose in production?"
A common beginner question. Docker Compose is excellent for local development, but here's what it lacks for production:
| Need | Docker Compose | Kubernetes |
|---|---|---|
| Multi-node deployment | ❌ Single host | ✅ Multi-node cluster |
| Self-healing | ❌ Manual restart | ✅ Auto-restart & reschedule |
| Scaling | ⚠️ Limited | ✅ HPA, VPA, cluster autoscaler |
| Rolling updates | ❌ Downtime on redeploy | ✅ Zero-downtime rolling update |
| Service discovery | ⚠️ Basic DNS | ✅ Built-in DNS + load balancing |
| Secret management | ⚠️ Env files | ✅ Encrypted secrets, RBAC |
Scenario: "My team deployed 50 containers manually and it keeps breaking"
This is exactly the problem Kubernetes solves. When your team manually manages containers:
- Someone forgets to restart a crashed container → users see errors
- A server goes down → half your app is unreachable
- A new version has a bug → painful manual rollback across servers
- Traffic spike hits → no way to auto-scale
Kubernetes handles all of this through its reconciliation loop: it continuously checks if reality matches the desired state and corrects any drift.
🎯 Interview Questions
Beginner
Kubernetes is an open-source container orchestration platform that automates deploying, scaling, and managing containerized applications. It's used because manually managing containers across servers doesn't scale — Kubernetes automates scheduling, self-healing, load balancing, rolling updates, and secret management.
Docker is a container runtime — it packages and runs individual containers. Kubernetes is an orchestration layer — it manages many containers across many machines. Docker builds and runs the container; Kubernetes decides where to run it, restarts it if it fails, scales it, and routes traffic to it. They work together, not as replacements.
K8s is a numeronym for Kubernetes — "K" + 8 letters + "s". It's shorthand used in the community. Kubernetes itself comes from the Greek word for "helmsman" or "pilot".
A cluster is a set of machines (nodes) that run containerized applications managed by Kubernetes. It consists of a Control Plane (master components that make scheduling decisions) and Worker Nodes (where the actual application containers run).
Desired state is what you declare in YAML manifests — for example, "I want 3 replicas of my app running image v2." Kubernetes continuously compares the actual state of the cluster to this desired state and takes corrective action (starts pods, kills pods, restarts crashed ones) to make them match.
Intermediate
Through the reconciliation loop. Controllers (like the Deployment controller) continuously watch the cluster state. If a pod crashes, the controller detects the mismatch between desired (3 replicas) and actual (2 running), and creates a new pod. If a node dies, pods are rescheduled to healthy nodes. Liveness and readiness probes provide additional health checking.
Imperative: You tell K8s what to do step by step: kubectl run nginx --image=nginx. Declarative: You define the desired state in a YAML file and kubectl apply -f it. Kubernetes figures out the steps. Declarative is preferred for production because manifests are version-controlled, reproducible, and auditable.
Kubernetes supports any CRI (Container Runtime Interface) compliant runtime. Common ones: containerd (default in most distros), CRI-O (lightweight, designed for K8s). Docker was used historically but was deprecated as a runtime in K8s 1.24 — though Docker-built images still work fine with containerd.
Namespaces provide logical isolation within a cluster. They let you divide resources between teams, environments (dev/staging/prod), or projects. Resource quotas and RBAC policies can be scoped to namespaces. Default namespaces: default, kube-system, kube-public, kube-node-lease.
Yes. Since K8s 1.24, Docker is no longer a supported runtime. Kubernetes uses the CRI (Container Runtime Interface) and typically runs with containerd or CRI-O. However, you can still build container images with Docker — the images are OCI-compatible and work with any runtime.
Scenario-Based
Docker Compose is single-host — it can't distribute containers across machines. In production you need multi-node deployment, automatic failover, scaling, rolling updates, and proper secret management. Kubernetes provides all of this plus a declarative model that integrates with CI/CD. Compose is great for local dev, but Kubernetes is designed for production resilience.
Without K8s: pager goes off, engineer SSHs in, manually restarts containers or moves them to another server. With K8s: the node controller detects the node is unhealthy, marks pods as terminated, scheduler automatically redistributes workloads to healthy nodes. Self-healing happens in seconds/minutes — no human intervention needed.
Configure a Horizontal Pod Autoscaler (HPA) to scale pods based on CPU/memory or custom metrics. If nodes run out of capacity, the Cluster Autoscaler adds more nodes. When traffic drops, both scale back down. This is reactive (metric-based) — for predictable events, you can also pre-scale by updating replica counts before the sale.
Kubernetes tracks deployment revision history. Run kubectl rollout undo deployment/myapp to instantly roll back to the previous working version. For more control: kubectl rollout undo deployment/myapp --to-revision=3. The rolling update strategy ensures zero downtime during both deploy and rollback.
Consider: Portability — K8s runs anywhere (cloud, on-prem, hybrid); ECS is AWS-only. Complexity — ECS is simpler if you're AWS-only; K8s has a steeper learning curve but more flexibility. Ecosystem — K8s has a massive ecosystem (Helm, operators, service mesh); ECS is more limited. Team skill — if the team knows K8s, use it. Vendor lock-in — K8s minimizes it; ECS creates AWS dependency. For multi-cloud or hybrid: K8s. For simple AWS-only workloads: ECS can be sufficient.
🌍 Real-World Use Case
A fintech startup runs 30 microservices processing payment transactions. Before Kubernetes, they deployed containers manually to EC2 instances with shell scripts. Problems:
- Crashed services required manual restart (took 15-30 minutes)
- Deployments caused 2-5 minutes of downtime
- Flash sales overwhelmed fixed infrastructure
- Scaling required provisioning new VMs manually
After migrating to Kubernetes (AKS):
- Self-healing restarts crashed pods in seconds
- Rolling updates provide zero-downtime deployments
- HPA auto-scales during peak traffic
- Helm charts standardize deployment across all 30 services
- Downtime dropped from hours/month to near-zero
📝 Summary
- Kubernetes is a container orchestration platform — it manages containers at scale
- Docker packages apps into containers; Kubernetes manages where and how they run
- K8s provides self-healing, scaling, rolling updates, service discovery, and secret management
- It uses a declarative model: you define desired state, K8s maintains it
- It's the industry standard used by every major cloud provider