Kubernetes Deployment Strategies: Rolling, Recreate, Blue-Green and Canary
Learn Kubernetes deployment strategies including RollingUpdate and Recreate, plus practical Blue-Green and Canary release patterns using Kubernetes Services.
Kubernetes Deployment Strategies
Rolling, Recreate, Blue-Green and Canary
A practical guide to choosing and implementing application release strategies on Kubernetes
Introduction
Updating an application in production is not simply a matter of replacing one container image with another. A release strategy determines how old and new versions coexist, how much capacity is available during the change, how quickly users are exposed to the new version, and how a rollback can be performed.
Kubernetes Deployments provide built-in support for two Deployment strategies: RollingUpdate and Recreate. Blue-Green and Canary are broader release patterns that can be implemented on Kubernetes using Deployments, Services, labels, traffic-management components, and—when needed—additional progressive-delivery tooling.
Understanding this distinction is important: RollingUpdate and Recreate are native Deployment strategy types. Blue-Green and Canary are deployment/release patterns rather than additional values for .spec.strategy.type.
1. What Is a Kubernetes Deployment?
A Kubernetes Deployment manages Pods through ReplicaSets and provides declarative updates for applications. When the Pod template changes, Kubernetes creates a new ReplicaSet and progressively moves the Deployment toward the desired state.
A Deployment rollout is triggered when the Pod template changes, such as when a container image or template labels are changed. Scaling a Deployment does not itself create a new revision.
kubectl get deployment
kubectl get rs
kubectl get pods
kubectl rollout status deployment/my-app
kubectl rollout history deployment/my-app
2. Why Deployment Strategy Matters
3. Kubernetes Deployment Strategies at a Glance
4. RollingUpdate: The Kubernetes Default
RollingUpdate is the default Deployment strategy. Kubernetes gradually scales down old ReplicaSets and scales up the new ReplicaSet. The rollout can be controlled using maxUnavailable and maxSurge.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
spec:
replicas: 4
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 80
For this four-replica example, maxUnavailable: 1 permits at most one unavailable Pod during the rollout, while maxSurge: 1 permits one Pod above the desired replica count during the rollout.
5. maxUnavailable
maxUnavailable specifies the maximum number of Pods that can be unavailable during a RollingUpdate. It can be an absolute number or a percentage. Kubernetes calculates percentage values by rounding down.
The default value is 25%. If maxSurge is 0, maxUnavailable cannot also be 0.
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
A lower maxUnavailable generally favors availability but may make the rollout slower. A higher value can make updates faster but reduces available capacity during the transition.
6. maxSurge
maxSurge specifies the maximum number of Pods that can be created above the desired replica count during a RollingUpdate. It can be an absolute number or a percentage. Kubernetes rounds percentage values up.
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
A higher maxSurge can accelerate replacement and give the new version more capacity to become ready, but it temporarily increases resource consumption.
7. RollingUpdate Example: How the Numbers Work
Suppose a Deployment has four replicas, maxUnavailable is 1, and maxSurge is 1. During the rollout, Kubernetes can temporarily have up to five Pods and must maintain the availability constraints defined by the rollout configuration.
Desired replicas: 4
maxUnavailable: 1
maxSurge: 1
Old version: gradually scaled down
New version: gradually scaled up
Maximum desired-plus-surge Pods: 5
Actual Pod counts can temporarily be affected by terminating Pods and their termination grace periods, so operators should not assume that resource consumption always equals replicas plus maxSurge at every instant.
8. Recreate Strategy
Recreate is the other native Deployment strategy. During an upgrade, Kubernetes terminates all existing Pods before creating Pods from the new revision.
spec:
strategy:
type: Recreate
Recreate is appropriate when the old and new versions cannot safely run at the same time, or when a deliberate service interruption is acceptable.
Simple mental model: old version stops, then new version starts.
Useful when concurrent versions would cause data or compatibility problems.
Creates a service interruption during the replacement.
Do not choose Recreate merely because it is simpler; confirm that downtime is acceptable.
9. RollingUpdate vs Recreate
10. Blue-Green Deployment
Blue-Green is a release pattern in which two environments represent two application versions. One environment serves production traffic while the other contains the candidate version. After the candidate is validated, traffic is switched to it.
+----------------+
Users ---------> | Kubernetes |
| Service |
+-------+--------+
|
+---------+---------+
| |
Blue / v1 Green / v2
current candidate
Before switch: Service -> Blue
After switch: Service -> Green
Kubernetes Services select backend Pods by labels. A Blue-Green implementation can therefore use separate Deployments with distinct version labels and a Service whose selector is changed to point at the desired version.
The exact traffic-switch mechanism depends on the application architecture and networking layer. A basic Service selector switch is simple, while Gateway/API gateway/service-mesh approaches can provide more sophisticated routing.
11. Blue-Green Kubernetes Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-blue
spec:
replicas: 3
selector:
matchLabels:
app: demo
version: blue
template:
metadata:
labels:
app: demo
version: blue
spec:
containers:
- name: app
image: myapp:v1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-green
spec:
replicas: 3
selector:
matchLabels:
app: demo
version: green
template:
metadata:
labels:
app: demo
version: green
spec:
containers:
- name: app
image: myapp:v2
apiVersion: v1
kind: Service
metadata:
name: demo-service
spec:
selector:
app: demo
version: blue
ports:
- port: 80
targetPort: 8080
After validating the green Deployment, the Service selector can be changed from version: blue to version: green. This is a simplified pattern; production traffic switching should account for readiness, connection draining, session behavior, caching, database compatibility, and observability.
12. Blue-Green Advantages and Trade-Offs
13. Canary Deployment
Canary deployment gradually exposes a new version to a small portion of production traffic or users before expanding exposure. The goal is to detect problems while the blast radius is limited.
Users
|
Traffic layer
/ v1 / 90% v2 / 10%
/ stable Pods canary Pods
Observe metrics
|
Increase / stop / rollback
A canary is fundamentally about traffic or user exposure, not merely running one new Pod. If a Service selects both old and new Pods, Kubernetes can distribute traffic among matching backends, but a basic Service does not provide a precise percentage-based canary control mechanism.
For controlled percentage routing, teams commonly use an ingress or gateway layer, service mesh, or progressive-delivery controller that supports the desired traffic-splitting semantics.
14. Simple Kubernetes Canary Pattern
A basic canary pattern can run two Deployments with different version labels. A traffic-management component then decides how requests are distributed between them.
Deployment: app-stable
labels: app=demo, version=stable
Deployment: app-canary
labels: app=demo, version=canary
Traffic layer
-> stable: majority
-> canary: small percentage
The exact YAML depends on the traffic-management technology. Kubernetes itself provides the Pod, Service, Deployment, and networking APIs; percentage-based progressive traffic control is not a native Deployment strategy field.
15. Canary Rollout Stages
- Deploy the new application version without immediately sending all production traffic to it.
- Expose a small, controlled percentage or selected group of users to the candidate version.
- Monitor error rate, latency, saturation, business metrics, logs, and application health.
- If the canary is healthy, increase exposure gradually.
- If the canary is unhealthy, stop the rollout and route traffic back to the stable version.
- After successful validation, make the new version the primary production version.
16. Blue-Green vs Canary
17. Deployment Strategy Decision Tree
Does the old and new version safely coexist?
|
Yes ----------------------------- No
| |
Need gradual replacement? Use Recreate
|
Yes
|
Can all traffic switch at once?
| |
Yes No
| |
Blue-Green Canary
|
For standard Kubernetes updates: RollingUpdate
This is a starting point, not a universal rule. Database compatibility, compliance requirements, infrastructure capacity, release frequency, and observability maturity should influence the final choice.
18. Health Checks Are Critical
A release strategy is only as reliable as the signals used to decide whether a new Pod is healthy. Kubernetes readiness probes control whether a Pod is considered ready to receive Service traffic. Liveness and startup probes address different failure-detection concerns.
For production rollouts, combine Kubernetes readiness with application-level metrics and logs. A Pod can be technically Ready while the application still has a functional defect that only business-level metrics reveal.
19. minReadySeconds and Progress Deadline
Deployment supports minReadySeconds, which specifies how long a newly created Pod must remain ready without its containers crashing before it is considered available. The default is 0.
Deployment also supports progressDeadlineSeconds. If a rollout fails to make progress within the configured period, Kubernetes reports a Progressing condition with reason ProgressDeadlineExceeded. The default is 600 seconds.
spec:
minReadySeconds: 10
progressDeadlineSeconds: 600
20. Rolling Update and Rollback
Deployment revisions are stored through the ReplicaSets controlled by the Deployment. By default, Kubernetes retains ten old ReplicaSets for rollback, although revisionHistoryLimit can be configured.
kubectl rollout history deployment/my-app
kubectl rollout undo deployment/my-app
kubectl rollout status deployment/my-app
A rollback restores the Deployment's Pod template to an earlier revision. It is important to distinguish application rollback from database rollback: reversing an application image does not automatically reverse database schema or data changes.
21. Pause a Deployment During a Release
A Deployment can be paused so that changes to its Pod template do not trigger new rollouts while it is paused. This can be useful when preparing or grouping changes before resuming the Deployment.
kubectl rollout pause deployment/my-app
kubectl rollout resume deployment/my-app
22. Real-World Scenario: Standard Web Application
Imagine an API running with ten replicas. The team releases version 2 of the application.
23. Real-World Scenario: Breaking Application Compatibility
Suppose version 2 cannot safely run at the same time as version 1 because of a strict compatibility constraint. A normal RollingUpdate may be unsafe because old and new Pods coexist during the transition.
Possible choices include Recreate when downtime is acceptable, or Blue-Green with an application and data design that allows the new environment to be validated before traffic is switched. The correct choice depends on the exact compatibility constraint.
24. Database Changes and Deployment Strategy
Application deployment strategy and database migration strategy should be designed together. A Blue-Green or Canary rollout does not automatically solve schema compatibility.
Prefer backward-compatible schema changes when old and new application versions must coexist.
Separate schema expansion from application behavior changes when practical.
Do not assume kubectl rollout undo can undo a database migration.
Test migration and rollback behavior before production.
Treat data migrations as a separate operational concern from replacing Pods.
25. Common Mistakes
26. Troubleshooting a Stuck RollingUpdate
- Run kubectl rollout status deployment/my-app.
- Run kubectl describe deployment my-app and inspect Conditions and Events.
- Inspect ReplicaSets with kubectl get rs.
- Inspect Pods with kubectl get pods and check Pending, ImagePullBackOff, CrashLoopBackOff, and readiness failures.
- Inspect Pod logs.
- Check resource requests, quotas, scheduling constraints, and image availability.
- Review maxUnavailable, maxSurge, minReadySeconds, and progressDeadlineSeconds.
- If the release is unsafe, stop or roll back according to the incident procedure.
kubectl rollout status deployment/my-app
kubectl describe deployment my-app
kubectl get rs
kubectl get pods
kubectl describe pod <pod-name>
kubectl logs <pod-name>
kubectl rollout undo deployment/my-app
27. Observability for Progressive Releases
- Deployment rollout status and Kubernetes Events.
- Pod readiness and restart counts.
- Application error rate.
- Request latency and throughput.
- CPU and memory utilization.
- Dependency failure rates.
- Business KPIs relevant to the application.
- Logs correlated with release version.
- Alerts that identify regression after a rollout.
28. Production Best Practices
- Use RollingUpdate as the normal starting point for compatible stateless workloads.
- Set maxUnavailable and maxSurge deliberately rather than accepting defaults without evaluation.
- Use readiness probes and realistic startup behavior.
- Set minReadySeconds when newly ready Pods need an observation period before being considered available.
- Use progressDeadlineSeconds to surface stalled rollouts.
- Keep a tested rollback procedure.
- Use Blue-Green when a clean environment-level switch and fast rollback are more valuable than minimizing duplicate capacity.
- Use Canary when progressive exposure and measured risk reduction are important.
- Use explicit traffic management for percentage-based canaries rather than assuming a basic Service provides exact traffic percentages.
- Design database migrations for the coexistence model required by the release strategy.
- Monitor both technical and business-level signals.
29. Interview Questions
What deployment strategies are natively supported by Kubernetes Deployment?
Answer: Recreate and RollingUpdate. RollingUpdate is the default.
What is maxUnavailable?
Answer: The maximum number of Pods that can be unavailable during a RollingUpdate.
What is maxSurge?
Answer: The maximum number of Pods that can be created above the desired replica count during a RollingUpdate.
What is the difference between Blue-Green and Canary?
Answer: Blue-Green maintains separate versions/environments and switches traffic between them; Canary progressively exposes a new version to a limited audience or traffic percentage.
Is Canary a native Deployment strategy type?
Answer: No. Deployment's strategy type supports RollingUpdate and Recreate. Canary is a broader release pattern implemented with traffic management and Kubernetes resources.
Can a basic Kubernetes Service perform an exact 10% canary split?
Answer: A basic Service selects matching Pods; it does not provide a native percentage-weight configuration for exact canary routing.
When would you choose Recreate?
Answer: When old and new versions cannot safely coexist and a service interruption is acceptable.
Why is readiness important during RollingUpdate?
Answer: Readiness helps determine whether a Pod is ready to receive Service traffic and whether it can count as available for rollout purposes.
Does kubectl rollout undo automatically reverse database changes?
Answer: No. It rolls back the Deployment's Pod template; database changes require their own migration/rollback strategy.
30. Scenario-Based Interview Questions
Your Deployment has 10 replicas. You set maxUnavailable: 30% and maxSurge: 20%. What do these settings mean?
Expected reasoning: maxUnavailable is calculated by rounding the percentage down, while maxSurge is calculated by rounding the percentage up. For ten desired replicas, these correspond to at most three unavailable Pods and two surge Pods under the rollout rules.
A new version passes Kubernetes readiness but error rate increases after release. What does this tell you?
Expected reasoning: Readiness alone is not sufficient to prove application correctness. Use application and business metrics to evaluate release health and stop or roll back the rollout when the release criteria are violated.
You need to release a high-risk version to only a small percentage of users. Which pattern is more suitable?
Expected reasoning: A Canary pattern is generally a better fit because it is designed for progressive exposure and controlled blast radius.
The old and new application versions cannot run together. Which native Deployment strategy should you consider?
Expected reasoning: Recreate, if the resulting downtime is acceptable. Otherwise, investigate an architecture that permits coexistence, such as a compatible migration or an appropriately designed Blue-Green release.
31. Practical Lab
- Create a Deployment with four replicas.
- Configure RollingUpdate with maxUnavailable: 1 and maxSurge: 1.
- Deploy version 1 of a simple application.
- Update the image to version 2.
- Observe the new ReplicaSet and old ReplicaSet during the rollout.
- Check rollout status and Pod readiness.
- Inspect rollout history.
- Perform a rollback.
- Repeat with Recreate and observe the difference.
- Design a Blue-Green example with two Deployments and a Service selector.
- Design a Canary architecture and identify which component would control traffic percentages.
kubectl apply -f deployment.yaml
kubectl rollout status deployment/my-app
kubectl get rs
kubectl get pods
kubectl set image deployment/my-app web=myapp:v2
kubectl rollout history deployment/my-app
kubectl rollout undo deployment/my-app
32. Final Comparison
33. Summary
Kubernetes gives Deployments two native replacement strategies: RollingUpdate and Recreate. RollingUpdate gradually replaces Pods and can control availability and temporary capacity with maxUnavailable and maxSurge. Recreate terminates the old Pods before creating the new revision and is appropriate when concurrent versions are unsafe or downtime is acceptable.
Blue-Green and Canary extend the release model beyond simple Pod replacement. Blue-Green separates old and new environments and switches traffic between them. Canary progressively exposes a new version to a limited audience before expanding it. These patterns require careful traffic management, application observability, and database compatibility planning.
The most important operational lesson is that a deployment strategy is not just a Kubernetes YAML setting. It is a release design involving application compatibility, traffic, health checks, capacity, observability, rollback, and data migration.
34. Suggested Next Kubernetes Articles
- Kubernetes Service Explained: ClusterIP, NodePort, LoadBalancer and Service Discovery
- Kubernetes Probes Explained: Liveness, Readiness and Startup Probes
- Kubernetes Ingress and Gateway API Explained
- Kubernetes ConfigMap and Secret Explained
- Kubernetes Horizontal Pod Autoscaler Explained
- Kubernetes Resource Requests and Limits Explained
- Kubernetes Scheduling Explained: Taints, Tolerations, Affinity and Anti-Affinity
Official References
Kubernetes Deployment documentation: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
Kubernetes Deployment update task: https://kubernetes.io/docs/tasks/run-application/update-deployment-rolling/
Kubernetes Service documentation: https://kubernetes.io/docs/concepts/services-networking/service/
Kubernetes Services and networking overview: https://kubernetes.io/docs/concepts/services-networking/