From the course: OpenShift Essential Training: Container Orchestration and Deployment

OpenShift templates

- Imagine you're assembling a piece of furniture. Instead of gathering all the parts and tools separately, you get the kit with everything included and clear instructions how to put it together. OpenShift templates work similarly. They bundle all the resources your application needs into one convenient package. Templates in OpenShift provide a structured approach to application deployment. Here's what makes them so useful. They are a collection of resources. Think of templates as kits that include all the essential pieces, pods, services, and persistent volumes to deploy your applications. Templates use placeholders like variables that can be filled with specific values, making them flexible for different environment. Templates are written in YAML or json, so they are easy to read and modify and they are highly customizable and you can adjust templates to fit the exact needs of your application. Using templates in OpenShift involves two key steps. First, we have OC process. Think of this step as readying your recipe. This command takes the template and substitutes variables with actual values to generate the resource definition files. And OC apply. Once you have the configuration, this command applies it to your cluster, ensuring all the resources are created and deployed correctly. Now let's see what templates can do within the demo. In this demo, we will first view available templates and process their resources. So, I will use the CRC start command. I will use the OC login command to log in as the cube admin, and I will copy the password and paste it. I will clear the screen. I'll create a new project called templates. And now, let's see if we have any available templates. So I will use the OC get command, templates -n for namespace, OpenShift. And we see we have a lot of templates we can use. I will clear the screen again and I will use OC process specifying the namespace, which is OpenShift, and the template which I want to process. And it's going to be httpd-example. And we can see the information within the template. So within this template, we can see we have multiple containers. We have the ports, which are 80, 84, the httpd. We have a route which will be created. We have a build config. So we have a huge amount of resources that will be created when we apply this template. I will clear the screen again. And now let's go into the second task of our demo. In the second task of our demo, we will customize and apply the template. So let's see how that goes. I will use OC process. And now, additionally, with the -p parameter, I'll change some attributes. So I'll specify the name will be set to myhttpd. I'll specify the namespace, which now will be called templates. And I will send this over to OC apply to apply the template. And we can see the service was created, the route was created, the build config was created. The deployment was created. We can clearly see it was created in the templates project. And it also has the name myhttpd as I have defined it. So it worked perfectly. And finally, let's move on to the last task where we will review all created resources. So I will use the OC get all command to see all resources which were created, and we can see all of them here. Now I will use the oc describe to describe the route, let's say called myhttpd. And we can see the description of the myhttpd route. I'll clear the screen. I'll rerun the command again. And now let's say we want to describe and get information on the service. Describe service, myhttpd, and we can see the service, its name, as well as its target port and ID. If I want to go into deep deployment, I use the oc describe deployment, and I specify myhttpd. And we can see information related to the deployment. And that's it. In just a few steps, we used an OpenShift template to create resources, customize it with parameters, and deployed it to an application. Pretty simple and pretty fast, right?

Contents