This tutorial will teach how to use Blue-Green deployments on Openshift Paas in order to create a parallel environment for your applications which can be replaced just by setting a property in your router configuration

Blue-green deployments are a proven approach to reduce the downtime caused when you are typically upgrading an environment. This is done by creating a parallel environment on which the new deployment can be installed while keeping your earlier version still running. If a problem is detected, and after the new deployment is verified, traffic can be switched over with the option to rollback.

blue green deploy openshift

Let's see in concrete a simple demo application running on WildFly 10, which is made up of two versions: the master branch and a new branch, named version2, which will be triggered.

From any available project execute the following command to create the first app named bluedeploy:

oc new-app wildfly~ --context-dir=wildfly-basic --name=bluedeploy

Now let's create the second app based on the version2

$ oc new-app wildfly~ --context-dir=wildfly-basic --name=greendeploy

Let's check that our Pods are done:

$ oc get pods
NAME                   READY     STATUS      RESTARTS   AGE
bluedeploy-1-build     0/1       Completed   0          1h
bluedeploy-1-kcp53     1/1       Running     0          1h
greendeploy-1-build    0/1       Completed   0          1h
greendeploy-1-lr88n    1/1       Running     0          1h

Ok now we will expose on the router the first service, named "bluedeploy" which is related to the application running on the master branch:

$ oc expose service bluedeploy --name=bluegreen

The following route will be created:

oc get routes
NAME        HOST/PORT                                 PATH      SERVICES       PORT       TERMINATION
bluegreen             bluedeploy     8080-tcp   

Now let's try to invoke our application which is running in the "demo" Web context:

$ curl

        <h1>Hello World from WildFly on Openshift</h1>      

So the index.jsp returned the landing page for the application in the master branch. Now you can use the "oc patch" command to vary the settings of your router so that it will switch to the "greendeploy" app:

$ oc patch route/bluegreen -p '{"spec":{"to":{"name":"greendeploy"}}}'

You should expect the route to be changed accordingly:

$ oc get routes
NAME        HOST/PORT                                 PATH      SERVICES       PORT       TERMINATION
bluegreen             greendeploy    8080-tcp

Let's check that we are serving the application in the other branch:

$ curl

        <h1>Hello World from WildFly on Openshift</h1>

        <h2>Version 2 Running!!!</h2>       

Great. So with little work we were able to handle a replacement between applications without an interruption of the service. In the next tutorial How to configure AB Deployments on Openshift we will learn another approach called AB deployments that can be used to spread the traffic between two applications.


Related articles available on

Openshift installation quick tutorial

IMPORTANT: This tutorial is now outdated. Openishift origin has b

Java EE example application on Openshift

In this tutorial we will learn how to deploy a Java EE applicatio

Running tomcat Docker image on Openshift

A common issue when porting Docker images on Openshift is that th

Deploy Docker images on Openshift

This tutorial will teach you how you can build and deploy a custo

Using Property files in your Openshift applications

A common need for most application is to store its configuration

Accessing Openshift services remotely

In this article we will learn how to connect to services running