0
0
Kubernetesdevops~10 mins

Blue-green deployments in Kubernetes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Blue-green deployments
Deploy Blue Version
Test Blue Version
Switch Traffic to Blue
Deploy Green Version
Test Green Version
Switch Traffic to Green
Retire Blue Version
Blue-green deployment switches traffic between two identical environments to reduce downtime and risk.
Execution Sample
Kubernetes
kubectl apply -f blue-deployment.yaml
kubectl apply -f green-deployment.yaml
kubectl patch service myapp -p '{"spec":{"selector":{"version":"green"}}}'
Deploy blue and green versions, then switch service traffic from blue to green.
Process Table
StepActionKubernetes ResourceState ChangeResult
1Apply blue deploymentDeployment bluePods created with label version=blueBlue version running
2Apply green deploymentDeployment greenPods created with label version=greenGreen version running alongside blue
3Service selector points to blueService myappSelector set to version=blueTraffic routed to blue pods
4Patch service to greenService myappSelector changed to version=greenTraffic switched to green pods
5Monitor green deploymentPods greenCheck pod health and logsGreen version stable
6Delete blue deploymentDeployment bluePods terminatedBlue version retired
💡 Blue version retired after traffic successfully switched to green
Status Tracker
ResourceInitial StateAfter Step 1After Step 2After Step 4Final
Deployment blueNot presentRunning pods with version=blueRunning pods with version=blueRunning pods with version=blueDeleted
Deployment greenNot presentNot presentRunning pods with version=greenRunning pods with version=greenRunning pods with version=green
Service myapp selectorNoneversion=blueversion=blueversion=greenversion=green
Key Moments - 3 Insights
Why do we keep both blue and green deployments running at the same time?
Both versions run simultaneously to allow testing the new version (green) without affecting live traffic, as shown in steps 2 and 3 in the execution table.
What happens if the green deployment has issues after switching traffic?
You can quickly switch back the service selector to blue version to restore traffic, because blue pods are still running until step 6.
Why do we patch the service selector instead of redeploying the service?
Patching the selector changes traffic routing instantly without downtime, as seen in step 4, making the switch smooth and fast.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does the service start routing traffic to the green deployment?
AStep 4
BStep 2
CStep 3
DStep 6
💡 Hint
Check the 'Service myapp' resource state changes in the execution table rows.
According to the variable tracker, what is the state of the blue deployment after step 4?
ANot present
BRunning pods with version=blue
CDeleted
DPods terminating
💡 Hint
Look at the 'Deployment blue' row under 'After Step 4' in the variable tracker.
If the service selector was patched back to version=blue after step 4, what would happen to traffic routing?
ATraffic would stop completely
BTraffic would route to both blue and green pods
CTraffic would route to blue pods again
DTraffic would route to green pods only
💡 Hint
Refer to how the service selector controls traffic routing in the execution table and variable tracker.
Concept Snapshot
Blue-green deployments use two identical environments: blue (current) and green (new).
Deploy new version to green while blue serves live traffic.
Switch service selector to green to route traffic instantly.
Keep blue running until green is stable, then retire blue.
This reduces downtime and risk during updates.
Full Transcript
Blue-green deployment is a method to update applications with minimal downtime. First, the blue version is deployed and serves live traffic. Then, the green version is deployed alongside blue. The service selector initially routes traffic to blue pods. When green is ready and tested, the service selector is patched to route traffic to green pods instantly. Blue pods remain running until green is stable, allowing quick rollback if needed. Finally, blue pods are deleted to complete the switch. This process ensures smooth updates by switching traffic between two identical environments.