OpenShift is a popular platform-as-a-service (PaaS) solution that allows developers to easily deploy and manage their applications. In this article, we will walk through the process of deploying a sample application in OpenShift using code.

Before we begin, it's important to note that you will need to have an OpenShift account and the OpenShift command-line interface (CLI) installed on your machine.

Step 1: Creating a new OpenShift project

The first step in deploying an application in OpenShift is to create a new project. A project is a logical space within OpenShift where you can create and manage your applications. To create a new project, open a terminal and run the following command:

oc new-project <project-name>

Replace <project-name> with the desired name for your project.

Step 2: Creating a new application

Once you have created a new project, you can now create a new application within that project. In this example, we will be deploying a sample Node.js application, but you can deploy any type of application that is supported by OpenShift. To create a new Node.js application, run the following command:

oc new-app nodejs:14~https://github.com/openshift/nodejs-ex.git

This command will pull the sample Node.js application from the OpenShift GitHub repository and deploy it to your project.

Step 3: Exposing the application to the internet

Once the application is deployed, it will only be accessible within the OpenShift cluster. To make it accessible to the internet, you will need to create a route. A route is a way to expose your application to the internet using a unique URL. To create a route, run the following command:

oc expose svc/nodejs-ex

This command will create a route for your application and display the URL in the terminal. You can now access your application by visiting that URL in a web browser

Step 4: Deploying updates to the application

Now that your application is deployed and accessible to the internet, you can easily deploy updates to it. To deploy an update, simply push the changes to the GitHub repository and run the following command:

oc rollout latest dc/nodejs-ex

This command will update the application with the latest changes from the repository.

In conclusion, OpenShift makes it easy to deploy and manage applications using code. With a few simple commands, you can quickly and easily deploy a sample application and make it accessible to the internet. Happy coding!

Recommended Posts