How to Deploy Application on OpenShift Cluster

How to Deploy Application on OpenShift Cluster

26 September 2023 0 By Anshul Pal

In this blog post, we will talk about How to Deploy Application on Openshift Cluster. Which serves as an enterprise-grade Kubernetes Platform designed to accelerate the deployment, creation, and scalability of applications.

Organizations have universally acknowledged the critical importance of prioritizing customer experience. Also speedy delivery as key factors for success in the business world. To achieve these objectives, they have widely embraced the utilization of Containers and Kubernetes technology. In fact, it’s noteworthy that a substantial majority, ranging from 60% to 70%, of organizations have already incorporated containers into their operations. Speaking specifically about containers, the effective management of these containerized applications demands robust solutions like Kubernetes.

What is OpenShift?

OpenShift, developed by RedHat/IBM, serves as a platform for the execution of containerized applications. Beneath its surface, OpenShift leverages the capabilities of an open-source Kubernetes engine.

In simpler terms, you can view OpenShift as a customized version of Kubernetes, bearing the Red Hat brand, and enriched with additional features and functionalities. It essentially functions as a Platform as a Service (PaaS) layer that is constructed on the foundation of Docker and Kubernetes. This PaaS empowers users to construct, evaluate, deploy, oversee, and operate applications based on containers in cloud environments.

Methods to Deploy Application on Openshift

There are several methods for deploying an OpenShift application. It’s totally depend on your requirements. Here we are providing some common methods:

  1. Using the Console: This approach involves the utilization of OpenShift’s Graphical User Interface (GUI). With just a few simple clicks within the interface, you can swiftly deploy your website or application.
  2. Using the CLI (Command Line Interface): OpenShift offers a Command Line Interface as well. With a handful of concise commands entered through the command line, you can efficiently deploy your application.
  3. Web Console: OpenShift provides a user-friendly web console that allows you to deploy applications with a few clicks. You can use the web console to create and manage your applications, pods, services, and routes. This method is great for those who prefer a graphical interface.
  4. GitOps: GitOps is a modern approach to managing infrastructure and applications using Git repositories. You can set up a GitOps workflow in OpenShift, where changes to your Git repository trigger automatic deployments and updates in your OpenShift environment. This method is ideal for ensuring that your application’s infrastructure is defined in code and version-controlled.
  5. Custom Scripts: For more advanced deployment scenarios, you can create custom deployment scripts or CI/CD pipelines that interact with the OpenShift API. This approach provides flexibility and customization options tailored to your specific needs.

Deploying Existing Containerized Applications

If you already have a containerized application that you want to deploy on OpenShift, you can use the oc new-app command. Here’s an example:

[user1@APalgorithm ~]$ oc new-app --docker-image=registry.access.redhat.com/rhel7-mysql57

This command creates a deployment configuration to manage the deployment process and runs the existing container image within your OpenShift cluster.

Managing the Complete Application Lifecycle with OpenShift

For those who want OpenShift to oversee the entire application journey, oc new-app can create both a build configuration and a deployment configuration. This approach covers everything from cloning a Git repository to building a container image and deploying it on the OpenShift cluster. Here’s an example:

[user1@APalgorithm ~]$ oc new-app https://github.com/apalgorithm/openshift/tree/master/apps/nodejs

In this case, OpenShift handles tasks like Git repository management, container image creation, and deployment.

Fine-Tuning with oc new-app Options

While oc new-app simplifies deployment, sometimes it may need additional guidance:

  • Version Ambiguity: If your Git repository contains code targeting multiple versions of a service, specify the version to avoid confusion.
  • Multiple Approaches: When your Git repository contains both a Dockerfile and application source code, explicitly mention your approach to prevent ambiguity.

The oc new-app command offers various options to fine-tune your deployment strategy, ensuring a seamless deployment process.

Resources Created by oc new-app

oc new-app doesn’t just deploy your application; it creates several essential resources:

  • Build Configuration: To build the application container image from source code or a Dockerfile.
  • Deployment Configuration: To manage the deployment process and run the containerized application.
  • Image Stream: Pointing to the generated image in the internal registry or an external registry.
  • Service: For all exposed ports in the application container image.

These resources initiate a series of processes that further create resources such as application pods.

Managing Resources

You can delete resources created by oc new-app using a single command without affecting other project resources:

[user1@APalgorithm ~]$ oc delete all -l app=test

You can also use the --name option to specify a custom name for the resources created by oc new-app.

Beyond oc new-app

OpenShift’s flexibility allows you to create multicontainer applications step by step. You can run oc new-app multiple times in the same project, gradually building your application piece by piece.

To inspect resource definitions without creating resources in the current project, use the -o option:

[user1@APalgorithm ~]$ oc new-app -o json registry.onionlinux.com/mycontainerimage

This provides resource definitions that can be customized and inserted into templates.

Image Streams for Efficiency

OpenShift recommends using image streams to refer to container images instead of direct references. Image streams store metadata, like available tags and image content checksums, enabling OpenShift to perform efficient operations like image caching and updates.

Creating an image stream is simple with the oc import-image command, and it improves the overall efficiency of your deployment processes.

In summary, OpenShift’s oc new-app command is a versatile tool for deploying containerized applications. It provides flexibility, fine-tuning options, and integrates seamlessly with the broader OpenShift platform, making it a valuable resource for application deployment and management.

Suggested Reads!