Kubernetes Deployment Strategies: Rolling, Blue-Green, and Canary
Jirayu Saengwannakool
· 10 min read
Choosing the right deployment strategy is crucial for maintaining high availability while shipping new features. Let's explore the main strategies available in Kubernetes.
Rolling Deployments
The default Kubernetes strategy. Gradually replaces old pods with new ones:
- Pros: Simple, resource-efficient, automatic rollback
- Cons: Slower rollout, version mixing during deployment
- Use when: Standard updates with backward compatibility
Blue-Green Deployments
Maintains two identical environments. Switch traffic all at once:
- Pros: Instant rollback, easy testing, no version mixing
- Cons: Requires double resources, database migration challenges
- Use when: Critical updates requiring instant rollback capability
Canary Deployments
Gradually shift traffic to new version while monitoring metrics:
- Pros: Risk mitigation, real-world testing, gradual rollout
- Cons: Complex setup, requires monitoring, longer deployment time
- Use when: High-risk changes or testing new features with real users
Implementation Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
spec:
containers:
- name: app
image: myapp:v2Best Practices
- Always implement health checks (readiness and liveness probes)
- Monitor metrics during deployments
- Automate rollback based on error rates
- Test in staging with same strategy
- Document rollback procedures