[OpenShift] – How to setup blue/green environment? POC of blue/green setup in Openshift.

Following a small example of this setup. (POC)

  • Create a project:


$ oc new-project bluegren

  • Create a new app based on a git source image to get cats images

$oc new-app --name='blue' --labels=name="blue" php~https://github.com/wkulhanek/cotd.git --env=SELECTOR=cats

  • Create a router to expose the blue pod service.

$oc expose service blue -l name=bluegreen

  • Open a new terminal and make a curl for this route/service as follow.

$ while true; do curl -s $(oc get route blue --template='{{ .spec.host }}')/item.php | grep "data/images" | awk '{print $5}'; sleep 1; done

  • Create a new app based on the same a git source image, however, which the same endpoint used above will return cities images. ( v2 of the same code source/application )

$oc new-app --name='green' --labels=name="green" php~https://github.com/wkulhanek/cotd.git --env=SELECTOR=cities

  • Edit the router to switch the router to point for the latest pod created (green).

$oc patch route/blue -p '{"spec":{"to":{"name":"green"}}}'</code>

  • Check that in the other terminal that the router starts to address all request for the second pod.

Screen Shot 2018-04-16 at 16.37.21

NOTE: It is possible to edit the route by the command $oc edit route <name>

Screen Shot 2018-04-16 at 16.42.05

For further information check the following docs:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s