1. Home
  2. Training Library
  3. DevOps
  4. Courses
  5. Deploying Containerized Applications with Red Hat OpenShift

Creating Routes

Developed with
Red Hat
Creating Routes
1h 40m

Containers - why all the hype? If you're looking for answers then this course is for you!

"Deploying Containerized Applications Technical Overview" provides an in-depth review of containers and why they've become so popular. Complementing the technical discussions, several hands-on demonstrations are provided, enabling you to learn about the concepts of containerization by seeing them in action.

You'll also learn about containerizing applications and services, testing them using Docker, and deploying them into a Kubernetes cluster using Red Hat OpenShift.


In this section we're going to look a little bit closer at the OpenShift resources called Routes. So as you recall routes build on top of services so they enable us to let our applications not only have a static IP address like the services do, we can also expose that to the greater Internet and we can give a DNS hostname to our route and that therefore will point to our service, which points to our pod. So you can see in our little chart down here, how the host is once we have a route exposed for our service so you can see the router pod at the top there. 

The way the networking is going to flow is from the host machine we can access the DNS hostname so www. you know my pod.com, it's going to direct it into the router pod. The pod is then going to point to the service that is associated with that router and that service will then point and load-balance to the pod that it seems fit and that it is associated with. 

So this is what a route looks like. Remember I mentioned that all of the resources in OpenShift are either yml or json files, so you always see this right at the top it'll define the kind of resource it is in this case this is a route. We have a name for our route which is quoteapp and this is the host name for the routes and it's going to be pointing to remember route points to a service, so this is the important part we are specifying that it's a Service and we're specifying the name of the Service. So remember we're always associating a route with a service. So how do you create a route, so the first thing you can do is you can do an oc create command and you can give it that JSON or yml file just like the one we were just looking at and you can use that to create a route. 

However the actual easiest way to do it is to just like I did in the previous demonstration is to is this oc exposed command when you already have a service and then all you need to do is provide the name of the service and it will create a route for you based on that service. Keep in mind that the oc new app does not automatically create a route for you, so it's a good general practice if you want a service to be exposed to the Internet. 

There's a lot of instances where you don't necessarily want this but for any front or customer-facing applications you're going to want that part of the app to be exposed. You're going to want to run the oc expose app. That's exactly why by the way oc new-app does not automatically assume you want to route because you don't necessarily want everything to be exposed. 

You know only the only the parts that are facing the end user. The hosting that is generated is created using the route name, the project name and then the default domain. So in this next demonstration that we're going to jump into right now I'll show you how changing the route name is going to affect the overall host name and we'll play a little bit with using routes in our applications. Okay so I'm already logged into my OpenShift instance, so the first thing I'm going to do is create a new project and I'll call it route. And in this project we are going to deploy a PHP application, we're going to use the source to image feature, so we're going to call oc new-app. I'm going to specify that I want to use specifically the 5.6 version of PHP so that's the base image that OpenShift is going to use to build my custom image from my source code. So then I'm going to pass in the URL to my Git repository services.lab.example.com/ php -helloworld, alright. So that's going to create a bunch of these OpenShift resources for us. 

It's going to create a service, and then create a buildconfig, a deployment config and we can watch those pods come up by running oc get pods -w. Alright so it looks like our pod is up and running, I can see that by running the oc get pods command, you can see that our builder pod has finished and that we have our actual PHP HelloWorld pod up and running. So if we did an oc get service, we can see the name of our service and what we want to do is we want to expose that service this is the IP address that's the IP address that our application is available on but we want to expose that by and create a route. 

So oc expose service php helloworld. Ok, so now we've got a route if I do oc get route, I can see it there I run oc describe route php helloworld. I can get a whole list here of information all about this route, I can see that it is pointing to the php helloworld service, I can see when it was created and I can see that the namespace which project it's in, as well as any label information that I wanted to configure, so it's useful way to get more information remember the OC described command. 

Okay so let's try hitting this route. I'm going to use curl php we can use the requested hostname php-helloworld- route.apps.clustered.lab.dot.example.com and we should be greeted with a helloworld message, great. Hello world. So we know that our app is working and we're able to access it from the route. 

Ok let's delete this route php helloworld and we are going to create a new route based on the same service php helloworld and we're just going to give it a different name. And you can see how OpenShift is generating the hostname is based on the name of the route. So if I run oc get route I can see xyz. So now the hostname is xyz-route and we can run this curl again I'm just going to adjust the name it's xyz-route instead and there we go we can still access our app using a different route. 

So that concludes our exercise, so join us in the next video I want to take a closer look at how the source to image feature of OpenShift works.

About the Author
Jeremy Cook
DevOps Content Lead
Learning Paths

Jeremy is the DevOps Content Lead at Cloud Academy where he specializes in developing technical training documentation for DevOps.

He has a strong background in software engineering, and has been coding with various languages, frameworks, and systems for the past 20+ years. In recent times, Jeremy has been focused on DevOps, Cloud, Security, and Machine Learning.

Jeremy holds professional certifications for both the AWS and GCP cloud platforms.