 In this video, we will talk about how to do blue-green deployments using OpenShift. But before getting into an example of doing blue-green deployments, let us first understand what blue-green deployments actually mean. One of the challenges that we have in general is being able to switch over from a current version of an application to a new version pretty quickly with minimal downtime. And there have been patterns that have come up on how to do that by minimizing the downtime. And blue-green deployments is one of those patterns. Let's take an example of an application that has a version 1 of application running and we will call this a blue version of application. So you are seeing a blue version of application which is frontended by a router, a end user or a client issues a call to your application by, let's say, typing in a URL and this router translates this URL into wherever the application is running and you get your application served. Now let's take an example of a change made to this application and that is the version 2 of the same application and we will treat that version 2 as a green deployment. Now let's say this green deployment is set up. It is equivalent to the production set up. Now once that green deployment is ready, what we would do is switch over the connection from the router to the green version of the application, the version 2 of the application and at the same time remove the connection to the version 1 of the application. That's called a blue-green deployment. It happens pretty quickly because all you need to do is go and make a change to the router so that the end user doesn't see any downtime. They are just seeing a sudden switch over of the traffic being routed to application version 2. Now let's say you switched over just now and you figured out that there is some issue and you have to roll back to the older version of the application. That's also very simple. You can just disconnect the green version and switch back to the blue version. That's the blue-green deployment. So you have two similar instances of your production application, one with blue version version 1 and the other with green version and you can switch between blue and green whenever you want. Now let us see how to achieve that in OpenShift version 3. Now I'm logged into my OpenShift environment and I'm in the project creation screen. I'm creating a new project. I'm naming my project as blue-green and I just give a display name and a short description and I'm saying create. This will create a new project with the name blue-green. Now once the project is created, we will deploy an application into this project. I have an example of a simple application that will, this is a PHP app. There is an index.php page. All it does is it paints a rectangle and it fills that rectangle with two different colors. So initially, let's say I would want to paint a blue rectangle, I'm going to change it to, so it's going to paint a rectangle and fill it with color blue. Now it will deploy this application into OpenShift. So let me get started. I will use the git URL and paste it here and since this is a PHP application, I'm selecting a PHP builder image and I'll call this blue version because, I'll name this blue because this is the blue version. This is version one of the application running. Now we will create a route for this application later because that's the key here. We want to switch the route from the blue to green or green to blue whenever we want. So we'll create a route separately and I'll show you how to do that. Now I'll leave the rest of the parameters as these and then say create. Now this initiates the S2I build process. It pulls the source code from this git repository and the build process will also pull the builder image, the PHP builder image and it will layer my code on the top of the builder image and it will create an application image and it will put that in the registry and then deploy it. I'll change to the project from my command line. I'll use the blue-green project that we just created. In a minute, you'll start seeing that the build gets initiated inside this project for the blue application that we just applied. So if I do OC get builds, I'll see that the blue one build is running. So let's look at what's going on in this build. So OpenShift has pulled my source code and it pulled the PHP application image and it created an application image based using my code and it is now trying to push the application image into the registry. This will take a minute and now the image is successfully pushed. You'll see that OpenShift starts deploying that application immediately and if I do OC get pods now, there is a blue application running. We did not create a route for this application. So let us try to create it now. Let's first look at the service. The service was deployed when we created this application. It is given the same name as the application blue. So we'll expose the service and I'll call this route blue-green, give a host name or the URL to access this application as blue-green. The reason I named it blue-green is because we are going to use the same route to switch between blue and green. Now this blue-green, as you can see, is the new route that got created and it is pointing to the service blue and this service is front-ending that pod which is going to draw a blue box. That's the version one of our application. So now that it is there, let's go and check. You can see that as soon as we added that route, that route is visible here on this OpenShift console. So let's try to invoke this application on our new tab. So this, as you can see, this image is actually creating a PNG. So let me flash PNG and you see here is a blue box. So this is the execution of that code that's right in here. So it's just drawing a box and filling it with blue color. Now let's go back and change the code. We are going to now create a version two of this application and I'm going to edit this code. I'll comment out the line that creates a blue box and I'll change it to the code that fills this rectangle with green color. I'll go back and deploy another application. So let me, I'm not overwriting this existing application. It will keep running. The pod that is running blue will continue to run and I'll create a new application with the same URL and I'm doing the same URL, but this time the code is different and I'm choosing PHP 5.5 and I'll select this image, do the same thing like before this time I'm going to call this green. So the application is being named green and since we are going to use the route that we created earlier, I'm not going to add a route for this app and I'll leave the rest of the stuff as is and say create. Now just like before this will take a minute to launch this application. It will build the code and it will deploy the code. So I'll pause this for a moment. Now I can see that the green build is now complete. Let me also check here. Green build is complete and let me also see if the application got deployed and the green pod is now running. Now if you look at the image here, it is still showing the blue image, right? That's because the route is pointing to the version one of the application. Now let's assume that this version two has been tested and it's ready to go and we are ready to switch over the route from pointing to from blue to green, right? What we'll do is we'll edit the route. We'll look at the list of routes. We named our route as blue green. So we'll edit this route. It is currently pointing to blue, right? So we'll change it to green. Let's see edit route go down to the spec part of it and I'll say the spec is saying that this hostname blue green.testv3.osclout.com is pointing to a service whose name is blue. Now I'll change this to green and I'll save and exit and that's it. You can see right behind on the screen that the URL, the name given to this, the route got transferred from blue to green, right? Now let's invoke this in a new tab. We need that rectangle thing now. If I refresh it, it's drawing a green box now, as simple as that. So when I wanted to switch over the application from blue to green, all I needed to do was go and edit the route, point it from blue to green and the route will now show that it is pointing to green. Now let's say there is something wrong with this green deployment and people don't like it. There is a defect or something and you need to switch back to the, you need to roll back to the older version, which is the blue deployment, right? So do the same exact thing like before, go get into the route, edit it, right? Go to the spec, change this from green to blue again and it's changed. Now come back. It's displaying the blue application now. So that's the blue green deployment. It's as simple as editing the route to switch from one version to another. Thanks for watching the video.