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 on OpenShift.

To demonstrate Blue/Green deployments, we'll again use the DC Metro application and adjusting some of the text elements on the page. Using your GitHub account, please fork the following https://github.com/RedHatGov/openshift-workshops project.

You should be comfortable deploying an app at this point, but here are the steps anyway, this lab uses the same forked project from lab 5

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 dc-metro-map/views/dcmetro.jade file in your repo.

image

We can change the text labels indicated by name of a color. If you want to change the label for the "Red Line", change line 22 from "Red Line" to "Silver Line". These changes will be easily viewable on the main screen on the upper right of the application.

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.

Wait for the "blue" application to become available before proceeding.

Now that we are satisfied with our change we can do the Green/Blue switch. With OpenShift services and routes, this is super simple. Follow the steps below to make the switch, since this is a short exercise both CLI and Web Console based methods are outlined below, choose the one you prefer.:

  1. Goto the terminal and type the following:
    $ oc edit route green
    
  2. This will bring up the Route configuration yaml. Edit the element "spec:". On the "to:" "name:" line, change its value from "green" to "blue":

    Example Before:

    spec:
        host: green-bluegreen-demo.apps.ocptest1.alliances.dynatracelabs.com
        port:
        targetPort: 8080-tcp
        to:
        kind: Service
        name: green
        weight: 100
        wildcardPolicy: None
    

    Example After:

    spec:
        host: blue-bluegreen-demo.apps.ocptest1.alliances.dynatracelabs.com
        port:
        targetPort: 8080-tcp
        to:
        kind: Service
        name: blue
        weight: 100
        wildcardPolicy: None
    
  1. As "Administrator", in the "bluegreen-demo" project, navigate to "Routes", and select "green"image
  2. In the Route detail page, click on Actions > Edit:
    image
  3. Edit the Route: change the "spec:" -> "to:" section "name:" from "green" to "blue", and click "Save"image

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.