Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 678 of 80210. Deployment Strategies and GitOpsFree lesson

Implementing Blue-Green Deployment Architecture

Configure parallel production environments to facilitate instantaneous traffic switching between two identical versions of your application.

In this lesson, you will learn how to configure parallel production environments to facilitate instantaneous traffic switching between two identical versions of your application.

The Concept of Blue-Green Deployment

At its core, a Blue-Green deployment strategy maintains two identical production environments. We label them "Blue" (the current live version) and "Green" (the incoming version). Because both environments are fully functional and identical in configuration, you can deploy the new version to "Green" without impacting the "Blue" users. Once testing confirms the Green environment is stable, you perform an instantaneous cut-over by updating your routing layer—such as a Kubernetes Service selector or an Ingress controller—to point traffic from Blue to Green.

Implementing in Kubernetes

In a Kubernetes cluster, we manage this by labeling our Pods and updating the Service selector dynamically. Imagine you have a Service with a selector version: blue. Your Blue pods are tagged with that label. To deploy the new version, you spin up a deployment of Green pods labeled version: green.

When you are ready to switch, you modify your Service manifest:

apiVersion: v1
kind: Service
metadata:
  name: app-service
spec:
  selector:
    version: green # Changing this from blue switches traffic instantly
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

Why This Matters for CI/CD

This pattern provides a critical safety net. Because the old (Blue) environment remains running after the switch, you possess an immediate rollback mechanism. If the Green environment encounters issues post-deployment, you simply revert the Service selector back to version: blue to restore the previous stable state instantly. This architecture effectively decouples the "deployment" of code from the "release" of traffic, satisfying our goal of zero-downtime operations while providing an audit trail of which version was serving traffic at any given time.

Key Takeaway: Blue-Green deployment creates a fail-safe environment by running two identical stacks in parallel, allowing for instantaneous traffic redirection and near-zero downtime rollbacks via simple selector updates.