Deployments
What are Deployments?
Deployments manage ReplicaSets and provide declarative updates for pods and ReplicaSets.
Key Features
- Rolling updates and rollbacks
- Scaling applications
- Self-healing capabilities
- Version management
Creating Deployments
Simple Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.21
ports:
- containerPort: 80
Advanced Deployment with Resources and Probes
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app-deployment
spec:
replicas: 3
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: web-app
image: nginx:1.21
ports:
- containerPort: 80
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 5
Deployment Management
# Create deployment
kubectl create deployment nginx --image=nginx
# Scale deployment
kubectl scale deployment nginx --replicas=5
# Update deployment image
kubectl set image deployment/nginx nginx=nginx:1.22
# Rollout status
kubectl rollout status deployment/nginx
# Rollout history
kubectl rollout history deployment/nginx
# Rollback to previous version
kubectl rollout undo deployment/nginx
# Rollback to specific revision
kubectl rollout undo deployment/nginx --to-revision=2
Next Steps
Learn about ConfigMaps and Secrets to manage application configuration.