From Docker to Kubernetes
AdvancedDocker runs containers on a single host. Kubernetes orchestrates containers across a cluster of hosts, providing auto-scaling, self-healing, rolling deployments, and service discovery at scale.
Overview
Docker Compose works well for a single machine or a few containers in development. In production with dozens of microservices, hundreds of instances, and multi-host deployments, you need an orchestrator. Kubernetes (K8s) is the industry-standard container orchestrator. It treats your container infrastructure as a cluster of nodes and uses declarative YAML manifests (Deployments, Services, Ingress) to describe desired state — Kubernetes continuously reconciles actual state to match desired state. Key concepts: Pod (smallest deployable unit, one or more containers), Deployment (manages replica count and rolling updates), Service (stable DNS + load balancing for a set of pods), and Ingress (HTTP routing rules to services).
Docker Compose → Kubernetes Concepts
There is a direct mapping between Docker Compose constructs and Kubernetes resources. Understanding this mapping makes Kubernetes much less intimidating.
Compose → Kubernetes
─────────────────────────────────────────────────────
docker-compose.yml → collection of YAML manifests
service (with image) → Pod template in a Deployment
replicas: 3 → replicas: 3 in Deployment
ports: "3000:3000" → Service (ClusterIP/NodePort/LoadBalancer)
volumes: named → PersistentVolumeClaim (PVC)
environment: vars → env in container spec
depends_on → initContainers or readiness probes
healthcheck → livenessProbe + readinessProbe
restart: always → restartPolicy: Always (default)
networks → Kubernetes networking (pods talk by service name)
# Convert Compose to K8s with Kompose:
kompose convert -f docker-compose.yml
# Generates: deployment.yaml, service.yaml, persistentvolumeclaim.yamlKubernetes Deployment + Service
A Deployment declares the desired number of pod replicas and the update strategy. A Service provides a stable cluster-internal IP and DNS name for a set of pods selected by label.
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-api
spec:
replicas: 3 # run 3 identical pod replicas
selector:
matchLabels:
app: my-api
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # create 1 extra pod before killing old
maxUnavailable: 0 # never reduce below 3 during update
template:
metadata:
labels:
app: my-api
spec:
containers:
- name: api
image: myregistry/api:v1.2.3 # pinned, not latest!
ports:
- containerPort: 8000
resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "1000m"
readinessProbe: # pod receives traffic only when ready
httpGet:
path: /health
port: 8000
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe: # restart pod if this fails
httpGet:
path: /health
port: 8000
initialDelaySeconds: 15
failureThreshold: 3
---
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: my-api
spec:
selector:
app: my-api # routes to all pods with this label
ports:
- port: 80
targetPort: 8000
type: ClusterIP # internal only; use LoadBalancer for externalWhen to Use Docker vs Kubernetes
Kubernetes is powerful but operationally complex. Choose the right tool for your scale.
Use Docker / Docker Compose when:
✅ Single machine or small VPS
✅ Local development environment
✅ Simple hobby projects / staging environments
✅ < 5 services, single team
✅ You want simplicity over features
Use Kubernetes when:
✅ Multiple hosts / cloud clusters needed
✅ > 10 services or microservices architecture
✅ Need auto-scaling (HPA: scale pods on CPU/custom metrics)
✅ Need rolling deployments with zero downtime
✅ Self-healing: automatic pod restart, node failure tolerance
✅ Multi-team, production SLAs
Managed Kubernetes (less operational burden):
AWS EKS → Elastic Kubernetes Service
GCP GKE → Google Kubernetes Engine (best managed K8s)
Azure AKS → Azure Kubernetes Service
Fly.io → containers without K8s complexity (great for small teams)
Railway → Compose-level simplicity with cloud deploymentKey Points to Remember
- 1Kubernetes orchestrates containers across a cluster; Docker runs containers on a single host.
- 2Pod is the smallest K8s unit — usually one container. Deployment manages replicas and rolling updates.
- 3Service provides stable DNS and load balancing for a set of pods selected by label.
- 4readinessProbe controls when traffic is sent to a pod; livenessProbe triggers pod restart.
- 5Use managed Kubernetes (EKS, GKE, AKS) in production to avoid managing the control plane.
- 6Start with Docker Compose for development; migrate to Kubernetes when you need multi-host orchestration and auto-scaling.
Interview Questions
Sign in to ask AriaWhat is the difference between a readinessProbe and a livenessProbe in Kubernetes?
How do you do a zero-downtime deployment in Kubernetes?
Ask Aria about From Docker to Kubernetes
Your personal AI tutor — ask anything about this concept
Revision Status
Personal Notes
Sign in to save personal notes for this topic.
Discussion
Sign in to join the discussion.