The purpose of this short lab is to demonstrate how simple it is to implement Blue-Green Deployments in OpenShift v3.
"Blue-green deployment is a release strategy that can be utilized by developers for deploying software in a production environment. Blue can be one particular production environment whereas green can define an identical production environment. Under blue-green deployment strategy, software developers are able to minimize downtime and reduce risk." 1*
In this Lab, we will be:
-
Deploying two versions of the same application. The first version will display a blue rectangle.
-
Create a FQDN that can be used to expose the applications.
-
We will first expose the first application.
-
We will also create another version of this application in the same project that displays a green rectangle.
-
We will then switch the FQDN to from the first application (blue) to the second application (green).
Step 1: Create a new project
Important
|
Please replace userxx with the username assigned to you in the commands below. IMPORTANT: Please replace userxx with your username |
-
login to web UI via https://master.ocp.tauil.org
-
Use the same username and password that assigned to you
-
Click
Create Project
-
Enter
bluegreen-userxx
as project name (all lower case)
-
Click
Create
Step 2: List existing image builder or image streams
-
Click
Add to Project
-→ selectBrowse Catalog
-
Click
PHP
-
Click drop down from the version under PHP and get the list of image stream
Step 3: Create an application
We will be using a sample application that displays a blue or green rectangle. The sample app can be browsed at https://github.com/RedHatWorkshops/bluegreen
We will be using an env var in order to change the color of the box; but in practice you would use a different branch for each version of the code. (E.g. v1 branch and v2 branch)
-
Click
Add to Project
-→ selectBrowse Catalog
-
Click
PHP
-
Click
Select
in the PHP option with the default version -
Enter name as
blue
-
Enter Git Repository URL as https://github.com/RedHatWorkshops/bluegreen
-
Click
advanced options
link below to expand the options area -
Scroll down to
Deployment Configuration
session -
Add
COLOR
as key andblue
as value
-
Scroll down and click
Create
Step 4: Monitor the application build
-
Click
Builds
-→Builds
-
Click onto
#1
-
Click
Logs
tabOnce the build finishes you should see something similar to:
... Pushing image docker-registry.default.svc:5000/guide/blue:latest ... Pushed 0/6 layers, 2% complete Pushed 1/6 layers, 27% complete Pushed 2/6 layers, 40% complete Pushed 3/6 layers, 53% complete Pushed 4/6 layers, 73% complete Pushed 4/6 layers, 92% complete Pushed 5/6 layers, 97% complete Pushed 6/6 layers, 100% complete Push successful ...
Step 5: Check application deployment status
-
Click
Applications
-→Pods
-
Pods
blue
showsRunning
Status
Notice that the build pod has Completed and you now have a single instance of the application running under one single pod.
This application displays a blue square.
Step 6: List the service
-
Click
Applications
-→Services
to view all services
Step 8: Test the application
-
Click
Overview
-
Click route link on the top right on the screen
At this point you have deployed an application that displays for illustration purposes a blue rectangle for version 1.
In this part, we will:
-
Deploy a new version of this application (Same one as before with a very small change)
-
Point the previously created FQDN (route) to the new service that will be created as part of the new application creation process.
Step 1: Create new version of the application
Create a new application the same way as you did above in Part I. Make sure to name the application as 'green' this time.
-
Click
Add to Project
-→ selectBrowse Catalog
-
Click
PHP
-
Click
Select
in the PHP option -
Enter name as
green
-
Enter Git Repository URL as https://github.com/RedHatWorkshops/bluegreen
-
Click
advanced options
link below to expand the options area -
Scroll down to
Deployment Configuration
session -
Add
COLOR
as key andgreen
as value -
Scroll down and click
Create
-
Wait until the application is built and deployed. You should now see two services on Overview
-
Step 2 Edit service
Edit the previously created route and change the service
name (from
blue
to green
), all the way at the bottom to the new service that
was just created. You are essentially still using the FQDN you had
previously created. However, that route will now point to a different
(green) service.
-
Click
Applications
-→Routes
-
Click
blue
-
Click
Actions
-→Edit
-
Select
green
under Service -
Click
Save
Step 2: Test the application
-
Click onto the Route URL
-
You should now see the new version of the recently deployed application with a green rectangle.
-
-
Blue-Green deployments can be easily accomplished in OpenShift v3.
-
We have shown multiple versions of an application; all running concurrently, each with a unique service.
-
All that is needed to expose any of the applications is to change the service being used by the route to publicly advertise the application.