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

Executing Blue-Green Deployments via Traffic Shifting

Perform zero-downtime blue-green deployments by switching the entire traffic load instantly between two isolated production environments using ingress traffic management.

In this lesson, you will learn how to orchestrate a true cutover by shifting your entire production traffic from a stable "Blue" environment to a newly verified "Green" environment using ingress-level routing.

The Blue-Green Philosophy

While canary releases focus on incremental exposure, a Blue-Green deployment focuses on an instantaneous switch between two identical production stacks. In a Kubernetes environment, "Blue" represents your current, live version, while "Green" represents the updated version sitting idle. Because both environments are fully provisioned and tested before the shift, the risk of a "partial" deployment failure is eliminated.

Traffic Shifting at the Ingress

The magic of the switch happens at the ingress layer. Instead of modifying the pods of your existing production deployment, you maintain two distinct Deployment objects. Traffic management is handled by updating the Ingress resource or a Service Mesh VirtualService to point to the new Service selector.

Consider this VirtualService configuration:

spec:
  http:
  - route:
    - destination:
        host: my-app-service
        subset: blue  # Currently live
      weight: 100
    - destination:
        host: my-app-service
        subset: green # Idle/Testing
      weight: 0

To execute the deployment, you perform a patch operation that flips the weights: setting blue to 0 and green to 100. Because this occurs at the Layer 7 routing level, the shift is atomic.

Why Use This Instead of Rolling Updates?

Unlike standard rolling updates—which slowly replace pods and can leave you in a "mixed version" state—Blue-Green deployments provide an isolated, predictable environment. If the Green environment behaves unexpectedly immediately after the shift, you can perform an instantaneous rollback by simply flipping the traffic weights back to Blue. This provides a clear, binary "safe" or "unsafe" state for your production traffic, making it the preferred pattern for monolithic applications or complex services that cannot tolerate version skew during the deployment window.

Key Takeaway: Blue-Green deployment via traffic shifting provides an instantaneous, atomic cutover between isolated environments, allowing for a risk-free, single-step rollback by simply reverting the ingress routing rules.