Course contentsShow
← C#
Lesson 1871 of 1,90817. Deployment and Cloud ArchitectureFree lesson

Implementing Blue-Green Deployment Patterns

Orchestrate traffic switching between two versions of an ASP.NET Core API.

In this lesson, you will learn how to orchestrate a seamless traffic cutover between two isolated environments—Blue (current) and Green (new)—to achieve near-zero downtime for your ASP.NET Core API.

The Blue-Green Philosophy

At its core, the Blue-Green pattern eliminates the risk of "in-place" updates by maintaining two identical production environments. The "Blue" environment runs the stable version (v1), while the "Green" environment runs your new release (v2). Traffic is only routed to Green once it has passed health checks. If an issue arises, you simply revert the load balancer or Ingress controller back to Blue instantly.

Orchestrating Traffic with Ingress

In an ASP.NET Core Kubernetes environment, we manipulate the Ingress resource to flip the switch. Since you have already mastered Configuring External Load Balancers with Ingress Controllers, you know that the rules section defines which service receives incoming traffic.

To implement the cutover, you maintain two distinct Service resources, each pointing to their respective deployment. Initially, your Ingress points to api-service-blue:

# Ingress configuration pointing to Blue
spec:
  rules:
  - host: api.example.com
    http:
      paths:
      - path: /
        backend:
          service:
            name: api-service-blue
            port: { number: 80 }

Executing the Switch

Once the Green environment is verified, you perform a declarative update to the Ingress resource, pointing the backend.service.name to api-service-green. By applying this change through your CI/CD pipeline, the Ingress controller updates the routing table globally. Because the Blue environment remains running (but idle), you maintain the ability to "roll back" in milliseconds by updating the Ingress to point back to the Blue service.

This pattern is highly effective for mission-critical .NET APIs where state consistency is managed externally (e.g., in a database or Redis), ensuring that your transition remains decoupled from the infrastructure deployment itself.

Key Takeaway: Blue-Green deployment relies on managing two identical production stacks and using the Ingress controller as a routing switch to perform an instantaneous, atomic cutover of user traffic.