Edited 3 months ago by ExtremeHow Editorial Team
OpenShiftKubernetesContainersDeploymentDevOpsRed HatCloudConfigurationCommand LineMulti-Cluster
This content is available in 7 different language
OpenShift is a popular open-source container application platform designed to easily orchestrate and manage containerized applications. Built on Kubernetes, OpenShift extends its functionalities with additional enterprise-ready features that make it a powerful solution for developers and IT teams who want to continuously deploy applications in hybrid environments. In this guide, we will explore the steps required to deploy applications using OpenShift on the Linux operating system. Our aim is to provide clear and simple instructions that even users with basic knowledge can understand and implement.
Before getting into the specifics of deployment, it is important to understand what makes OpenShift an exceptional platform. OpenShift is essentially a Platform-as-a-Service (PaaS) offering from Red Hat based on Docker containers and Kubernetes. This means that OpenShift uses containerization to ensure that your applications can be developed, shipped, and deployed more efficiently, while Kubernetes provides orchestration, managing all these containers effectively.
OpenShift provides an environment where developers can focus on writing code, while the platform handles operational aspects such as scaling, monitoring, and load balancing.
Before you start deploying applications on OpenShift, you need to fulfill a few pre-requisites:
oc
command line tool) must be installed on your machine.With these prerequisites in place, we can proceed to deploy the application on OpenShift.
First, you need to log into your OpenShift cluster. For this you will use oc
command-line tool. Open your terminal and enter the following command:
$ oc login https://<your-openshift-api-url> --token=<your-login-token>
You'll need to replace <your-openshift-api-url>
and <your-login-token>
with your specific API server URL and authentication token. Authentication tokens can usually be found in your OpenShift console under your user settings.
In OpenShift, applications are deployed within a project. Think of a project as a workspace or sandbox where you can manage resources, users, and applications.
Use the following command to create a new project:
$ oc new-project my-nodejs-app --display-name="My NodeJS App" --description="This project deploys a NodeJS application"
This command creates a new project named my-nodejs-app
with the display name and description.
OpenShift provides you with several ways to deploy an application. The easiest way is to use oc new-app
command.
Suppose you have a Node.js application. You can deploy it like this:
$ oc new-app nodejs:12~https://github.com/username/my-nodejs-app.git
This command tells OpenShift to create a new application using Node.js version 12 and pull from the specified GitHub repository. The tilde symbol (~
) is used to specify that OpenShift should use source-to-image (S2I) to build an image from the source code in the given repository.
By default, applications deployed on OpenShift are not accessible externally. To allow access to your app via the Internet, you must create a route for it.
Use this command to display your service:
$ oc expose svc/my-nodejs-app
This will create an OpenShift route based on your service, making your application accessible from an external URL. To check the URL, use:
$ oc get route
Open your browser and visit the URL to see if your application is running correctly.
OpenShift allows you to easily scale applications to handle more traffic. Scaling is the process of increasing or decreasing the number of container instances (replicas) based on the needs of your application.
To increase the number of instances, use:
$ oc scale --replicas=3 deployment/my-nodejs-app
This will increase your deployment to 3 instances. With more replicas, OpenShift can effectively balance the load across each replica.
OpenShift also provides options for automatic scaling based on CPU usage with the Horizontal Pod Auto-Scaler features.
Monitoring applications in a production environment is important. OpenShift provides several tools and interfaces for monitoring.
oc logs <pod-name>
to view the logs of a particular container. This helps to debug issues and inspect the flow of your application.Use these monitoring tools to make sure your application is running smoothly and to troubleshoot any issues that may arise.
One of the benefits of using OpenShift is that the process for application updates is simplified. You can implement continuous integration and delivery (CI/CD) pipelines that automatically deploy updates to your applications.
For manual updates, if you want to update your application, it often means updating the source image. Suppose you have made new changes to your Git repository, then trigger a new build on OpenShift:
$ oc start-build my-nodejs-app
This command initiates a new build for your application. After the build is complete, OpenShift automatically rolls out the changes to the running instance.
Deploying applications on OpenShift using Linux is a powerful way to take advantage of the scalability, stability, and easy management of containerized applications. By following a structured setup and deployment as explained in this guide, you can harness the full potential of OpenShift.
Remember, this is just a starting point. OpenShift supports a wide range of capabilities, including running stateful applications, complex networking configurations, and integration with other services. As you become more comfortable with basic deployments, explore these advanced features to get the most out of OpenShift.
With a strong community and extensive documentation, you are in good hands to solve any challenges or requirements you may face in deploying applications on OpenShift.
If you find anything wrong with the article content, you can