Blue/Green Deployment

Updated 3 weeks ago by Michael Cretzman

In a Blue/Green deployment, network traffic to your service/artifact is routed between two identical environments called blue (staging) and green (production). Both environments run simultaneously, containing different versions or the service/artifact.

QA and User acceptance testing (UAT) are typically done on the blue environment. When satisfied, traffic is flipped (via a load balancer) from the green environment (current version) to the blue environment (new version). Once deployment is successful, you can decommission the old environment.

The greatest benefit of a Blue/Green deployment is Rapid Rollback: rolling back to the old version of a service/artifact is simple and reliable because network traffic is simply routed back to the original instances. You don't need to redeploy previous versions of the service/artifact and the instances that comprised their environment.

Kubernetes and Blue/Green

The default setup and configuration required for Blue/Green deployments is available in Harness out-of-the-box. The only requirement or pre-requisite is that you use Kubernetes to deploy your service artifacts. The Blue/Green workflow spins up the same number of instances in your blue (staging) environment that are already running in your green (production) environment.

Intended Audience

  • DevOps

Before You Begin

To Create a Blue/Green Deployment

The following procedure creates a workflow using the Blue/Green deployment type. The services, artifacts, environments, and Kubernetes service infrastructure in the procedure are pre-existing.

To create a Blue/Green deployment, do the following:

  1. Create a new Blue/Green workflow.
    1. Click Setup, and then click the application where you want to add the Blue/Green deployment workflow.
    2. Click Workflows, and then click Add Workflow. The Workflow dialog appears.
    3. Name your workflow blue-green-deployment.
    4. In Workflow Type, select Blue/Green Deployment.
    5. In Environment, select a deployment environment.
    6. In Service, select a service to deploy.
    7. In Service Infrastructure, pick the service infrastructure.
    8. Click SUBMIT. The Blue/Green workflow is added. Your Blue/Green deployment is ready. The Stage Deployment step is where Harness stages the Kubernetes service before swapping it with the primary, production service.

      The Swap Primary with Stage step is where it flips the switch and reroutes traffic to the verified service/artifact and environment. Click Swap Primary with Stage to see how the workflow uses placeholders for the two service environments, and swaps them.

  2. Add verification steps and other options. In order for the Blue/Green deployment to function correctly, you must verify that the new version meets adequate criteria. You do this by adding verification steps:
    1. Automate verification: Harness can automate the verification (health checks) of your Blue/Green deployment. Once your Blue/Green deployment sets up and deploys the containers in your blue (staging) environment, you can run Harness Continuous Verification using your existing APM and log management tools to validate your Blue/Staging deployment in real-time. See Verify Steps.
    2. Approvals: Manual approvals can also be added after verification has completed. These allow you to manually flip the switch (reroute traffic using your load balancer) when you are ready so that all traffic gets directed from the green environment (current version) to the blue environment (new version).
  3. Add other options:
    1. Rollback Strategy: Rollback Steps can be added to flip the switch back again should your deployment fail in the future. See Rollback Steps.
    2. Workflow Template: Blue/Green deployment workflows can also be turned into templates that other teams can reuse. For example, you could introduce the artifact and environment as workflow variables that can be later injected at deployment time by each dev team using CURL or Webhooks. See Template a Workflow.
      Many Harness customers create gold templates for deployments and then use RBAC to assign these templates to each Dev team for rollout and scale. Create once, deploy many times is typically the best practice instead of having a separate deployment workflow for each artifact and environment.
  4. Execute the Blue/Green deployment.
    Once the Blue/Green deployment is run, you can attach it to a pipeline or trigger. For more information, see Add a Pipeline and Add a Trigger.

How did we do?