4 Hours

6. Deployment Strategies: Blue-Green, Canary, and Rolling

Deployment

Deployment strategies determine how new versions of an application are rolled out to users. Choosing the right strategy is essential for minimizing risk and downtime. This module covers the three most common strategies: Rolling Updates, Blue-Green Deployments, and Canary Deployments.

The key insight is that different deployment strategies offer different trade-offs between speed, risk, and complexity. Rolling updates are the simplest but can cause downtime. Blue-green deployments eliminate downtime but require double the resources. Canary deployments reduce risk but are more complex. Understanding these strategies is essential for production-grade CI/CD.

This module covers each strategy in depth, with examples using Kubernetes and other platforms.

Rolling Updates

Rolling updates are the simplest deployment strategy. New versions are gradually rolled out by replacing old pods with new ones. This strategy has no downtime and uses only one environment. However, during the rollout, both old and new versions are running simultaneously, which can cause issues if there are breaking changes between versions. Rolling updates are suitable for applications with backward-compatible changes.

In Kubernetes, rolling updates are the default deployment strategy. You configure the strategy using the deployment spec, setting parameters like maxSurge and maxUnavailable. Understanding rolling updates is essential for basic Kubernetes deployments.

Blue-Green Deployments

Blue-Green deployments use two identical environments. The blue environment runs the current version. The green environment runs the new version. After testing the green environment, traffic is switched from blue to green. This strategy eliminates downtime and provides a quick rollback (just switch back to blue). The downside is double the resource usage.

In Kubernetes, blue-green deployments can be implemented using services and selectors. The service points to either the blue or green pod set. Traffic is switched by updating the service selector. Understanding blue-green deployments is essential for zero-downtime releases.

Canary Deployments

Canary deployments gradually roll out changes to a small subset of users before a full rollout. This reduces risk by catching issues early. Canary deployments can be controlled by percentage (e.g., 5%, 10%, 50%, 100%) or by user segment. If issues are detected, the rollout can be stopped and the canary is removed.

In Kubernetes, canary deployments can be implemented using multiple services and traffic management (e.g., Istio, Linkerd). They can also be implemented using Argo Rollouts, which provides advanced rollout strategies. Understanding canary deployments is essential for high-risk releases.

Step-by-Step: Implementing Deployment Strategies

Follow these steps to implement different deployment strategies.

Rolling Update (Kubernetes):
apiVersion: apps/v1<br>kind: Deployment<br>spec:<br> replicas: 3<br> strategy:<br> type: RollingUpdate<br> rollingUpdate:<br> maxSurge: 1<br> maxUnavailable: 0

Blue-Green (Kubernetes):
# Blue deployment<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br> name: app-blue<br>spec:<br> replicas: 3<br> selector:<br> matchLabels:<br> app: myapp<br> version: blue
# Service pointing to blue<br>apiVersion: v1<br>kind: Service<br>spec:<br> selector:<br> app: myapp<br> version: blue
When ready, update the service selector to point to green.

Canary (Argo Rollouts):
apiVersion: argoproj.io/v1alpha1<br>kind: Rollout<br>spec:<br> strategy:<br> canary:<br> steps:<br> - setWeight: 10<br> - pause: {duration: 5m}<br> - setWeight: 50<br> - pause: {duration: 5m}<br> - setWeight: 100

Try It Yourself: Deploy a simple application using each strategy. Observe the behavior during deployment. Practice rolling back a deployment.

Knowledge Check

Ready to test your understanding of 6. Deployment Strategies: Blue-Green, Canary, and Rolling?

Back