Container Orchestration Basics: Docker Compose to Kubernetes
Container Orchestration Basics: Docker Compose to Kubernetes
Container orchestration manages the lifecycle of containers at scale — deployment, scaling, networking, and health monitoring. Understanding when to move from Docker Compose to Kubernetes helps you choose the right tool for your stage.
Docker Compose: The Starting Point
Docker Compose defines multi-container applications in a single YAML file. It is ideal for development, small deployments, and single-server production:
docker-compose.yml
services:
web:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgresql://user:pass@db:5432/app
depends_on:
db:
condition: service_healthy
db:
image: postgres:16-alpine
volumes:
- pgdata:/var/lib/postgresql/data
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: app
healthcheck:
test: ["CMD-SHELL", "pg_isready -U user"]
interval: 5s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
volumes:
- redisdata:/data
volumes:
pgdata:
redisdata:
When Docker Compose Is Enough
When to Graduate to Kubernetes
Consider Kubernetes when you need:
Kubernetes Core Concepts
Pods
The smallest deployable unit. A pod runs one or more containers:
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
containers:
- name: web
image: myapp:latest
ports:
- containerPort: 3000
Deployments
Manage replicas and rolling updates:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: myapp:1.2.0
ports:
- containerPort: 3000
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "500m"
Services
Expose pods to the network:
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 3000
type: LoadBalancer
The Middle Ground: Docker Swarm
Docker Swarm is Docker's built-in orchestration. It is simpler than Kubernetes but supports multi-node clusters:
Initialize swarm
docker swarm init
Deploy a stack (uses docker-compose.yml)
docker stack deploy -c docker-compose.yml myapp
Scale a service
docker service scale myapp_web=5
Decision Framework
| Need | Docker Compose | Docker Swarm | Kubernetes |
|------|---------------|--------------|------------|
| Single server | Yes | Overkill | Overkill |
| 2-5 servers | Possible | Good fit | Possible |
| 10+ servers | No | Possible | Best fit |
| Auto-scaling | No | Limited | Yes |
| Learning curve | Low | Medium | High |
| Managed options | No | No | GKE, EKS, AKS |
Getting Started with Kubernetes
Use a managed Kubernetes service to avoid cluster administration:
Google Kubernetes Engine
gcloud container clusters create my-cluster --num-nodes=3
Apply your manifests
kubectl apply -f k8s/
Check status
kubectl get pods
kubectl get services
Conclusion
Start with Docker Compose for development and single-server deployments. Move to Kubernetes when you need multi-node scaling, self-healing, and zero-downtime deployments. Use managed Kubernetes (GKE, EKS, AKS) to avoid the operational overhead of running your own cluster.