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.
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:
- Create a new Blue/Green workflow.
- Click Setup, and then click the application where you want to add the Blue/Green deployment workflow.
- Click Workflows, and then click Add Workflow. The Workflow dialog appears.
- Name your workflow blue-green-deployment.
- In Workflow Type, select Blue/Green Deployment.
- In Environment, select a deployment environment.
- In Service, select a service to deploy.
- In Service Infrastructure, pick the service infrastructure.
- 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.
- 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:
- 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.
- 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).
- Add other options:
- Rollback Strategy: Rollback Steps can be added to flip the switch back again should your deployment fail in the future. See Rollback Steps.
- 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.
- 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.