Docker to Kubernetes: A Migration Guide for Developers
So you’ve mastered Docker and now you’re ready for Kubernetes. This guide will help you transition smoothly from Docker’s single-host container management to Kubernetes’ powerful orchestration platform.
Docker vs Kubernetes: Understanding the Difference
| Aspect | Docker | Kubernetes |
|---|---|---|
| Scope | Single host | Multiple hosts (cluster) |
| Scaling | Manual | Automatic |
| Networking | Bridge network | Overlay network + Services |
| Self-healing | No | Yes (restarts failed containers) |
| Load Balancing | Manual | Built-in |
Mapping Docker Concepts to Kubernetes
Docker Container → Kubernetes Pod
# Docker
docker run -d --name nginx -p 80:80 nginx
# Kubernetes
kubectl run nginx --image=nginx --port=80Docker Compose → Kubernetes Manifests
docker-compose.yaml:
version: '3'
services:
web:
image: nginx
ports:
- "80:80"
redis:
image: redisKubernetes equivalent:
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 1
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 80Converting Docker Compose with Kompose
# Install Kompose
curl -L https://github.com/kubernetes/kompose/releases/download/v1.28.0/kompose-darwin-amd64 -o kompose
# Convert docker-compose.yaml
kompose convert
# Apply generated manifests
kubectl apply -f .Key Kubernetes Concepts for Docker Users
1. Pods (Not Just Containers)
A Pod can contain multiple containers that share:
- Network namespace (localhost communication)
- Storage volumes
- Lifecycle
2. Deployments (Scaling Made Easy)
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3 # Kubernetes maintains 3 instances
selector:
matchLabels:
app: my-app3. Services (Internal Load Balancing)
apiVersion: v1
kind: Service
metadata:
name: my-app
spec:
selector:
app: my-app
ports:
- port: 804. ConfigMaps and Secrets
# Docker
docker run -e MY_VAR=value nginx
# Kubernetes ConfigMap
kubectl create configmap my-config --from-literal=MY_VAR=valueMigration Checklist
- Containerize with multi-stage builds
- Remove host dependencies
- Use environment variables for configuration
- Define health checks (liveness/readiness probes)
- Set resource requests and limits
- Plan for stateless design (use PVCs for state)
Practice the Migration
The best way to learn Kubernetes is hands-on practice. Sailor.sh provides:
- Real Kubernetes clusters
- Docker and Helm labs
- Migration scenarios
Start your Kubernetes journey: Sailor.sh