Blue | Green Deployment

View source on GitHub

Blue/Green deployments

When implementing continuous delivery for your software one very useful technique is called Blue/Green deployments. It addresses the desire to minimize downtime during the release of a new version of an application to production. Essentially, it involves running two production versions of your app side-by-side and then switching the routing from the last stable version to the new version once it is verified. Using OpenShift, this can be very seamless because using containers we can easily and rapidly deploy a duplicate infrastructure to support alternate versions and modify routes as a service. In this lab, we will walk through a simple Blue/Green workflow with an simple web application on OpenShift.

Let’s deploy an application

To demonstrate Blue/Green deployments, we’ll use a simple application that renders a colored box as an example. Using your GitHub account, please fork the following project.

You should be comfortable deploying an app at this point, but here are the steps anyway:

Goto the terminal and type these commands:

$ oc new-app --name=green [your-project-repo-url] --context-dir=dc-metro-map
$ oc expose service green

Note that we exposed this application using a route named “green”. Navigate to your application and validate it deployed correctly.

Release a new version of our app and test it in the same environment

What we’ll do next is create a new version of the application called “blue”. The quickest way to make a change to the code is directly in the GitHub web interface. In GitHub, edit the image.php file in the root directory of your repo.

Switch the commented out line to change the color of the rendered box (lines 9-10). Commit your changes.

Use the same commands to deploy this new version of the app, but this time name the service “blue”. No need to expose a new route – we’ll instead switch the “green” route to point to the “blue” service once we’ve verified it.

Goto the terminal and type these commands:

$ oc new-app --name=blue [your-project-repo-url] --context-dir=dc-metro-map

Switch from Blue to Green

Now that we are satisfied with our change we can do the Blue/Green switch. With OpenShift services and routes, this is super simple. Follow the steps below to make the switch:

Goto the terminal and type the following:
$ oc edit route green
This will bring up the Route configuration yaml. Edit the element spec: to: name and change it's value from "green" to "blue".
Navigate to the Routes view from the left-hand menu:

In your Routes overview, click on the "green" route:

In the Route detail page, click on Actions > Edit YAML:

Edit the YAML element spec: to: name: and change the value from "green" to "blue":

Summary

Pretty easy, right?

If you want to read more about Blue/Green check out this post with a longer description as well as links to additional resources.