Hands-on Implementation
Prerequisite Setup
Environment Requirements
- Ubuntu 22.04 LTS
- Kubernetes cluster
- kubectl installed
- Docker configured
Step-by-Step Rolling Update Process
1. Create Sample Application
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp
spec:
replicas: 3
selector:
matchLabels:
app: webapp
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: webapp
image: nginx:1.19.0
ports:
- containerPort: 80
2. Apply Initial Deployment
kubectl apply -f webapp-deployment.yaml
Update Strategy Configuration
graph LR
A[Initial Version] --> B[Update Trigger]
B --> C[Gradual Replacement]
C --> D[New Version Deployment]
## Update image version
kubectl set image deployment/webapp webapp=nginx:1.21.0
## Monitor update progress
kubectl rollout status deployment/webapp
Rollback Mechanisms
Undo Recent Update
## Rollback to previous revision
kubectl rollout undo deployment/webapp
## Rollback to specific revision
kubectl rollout undo deployment/webapp --to-revision=2
Advanced Update Strategies
Strategy |
Description |
Use Case |
Canary |
Partial version deployment |
Low-risk updates |
Blue-Green |
Parallel environment switch |
Zero-downtime releases |
Rolling Update |
Gradual pod replacement |
Standard deployments |
Checking Deployment Status
## View rollout history
kubectl rollout history deployment/webapp
## Describe deployment details
kubectl describe deployment webapp
Best Practices for LabEx Environments
- Use declarative configurations
- Implement comprehensive health checks
- Configure resource limits
- Plan rollback strategies
Health Check Example
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 10
periodSeconds: 5
Common Troubleshooting
Handling Update Failures
- Check pod events
- Verify image availability
- Review resource constraints
## Investigate pod issues
kubectl get pods
kubectl describe pod <pod-name>
- Use minimal container images
- Implement multi-stage builds
- Configure appropriate resource requests
- Use horizontal pod autoscaling
Conclusion
Successful Kubernetes rolling updates require:
- Careful planning
- Robust configuration
- Continuous monitoring
- Flexible strategy implementation
By following these guidelines, developers can achieve seamless application deployments in Kubernetes environments.