Getting Started with OpenShift

 

OpenShift

 

Many Rafay Systems customers use Red Hat OpenShift as their platform of choice for building, deploying, running and scaling Kubernetes containerized applications. OpenShift is flexible and versatile; it can be deployed in public and private clouds, using physical or virtual servers, or both. OpenShift has proven to be of great value for operations and development teams. But getting started with OpenShift can be somewhat daunting. 

Overview

This blog will help you to get started with OpenShift to create an application, configure Continuous Integration (CI) and scale the application on-demand.

First, we will setup a sample Node.js application on an OpenShift cloud. Before starting, you should have the following:

 

Basic Setup

To start, you need to fork the OpenShift Node.js sample application on GitHub and clone the repository to your local environment so that you can deploy and make modifications to the application.

  1. On GitHub, fork a Github repository (OpenShift/nodejs-ex) by clicking on the top-right corner button on the page.

Basic Setup1

 

  1. Copy the URLs from GitHub

Basic Setup 2

 

  1. Now, execute the command below on your local terminal to check out the sample application and go to the new directory.

Basic Setup 3

 

Now, you have the local copy of the GitHub repository. You can you can make modifications and deploy on OpenShift.

 

Getting Familiar with the OpenShift Web Interface

To get familiar with the OpenShift online GUI, visit -> https://docs.OpenShift.com/online/architecture/infrastructure_components/web_console.html#architecture-infrastructure-components-web-console

 

Build a New Application

To build a new app, setup a Nodejs application using the web interface on OpenShift Online as follows:

1. Click on “Create Project”. If you are using a free account and already have a project, you must delete your existing project as only one project is allowed.

Build a new app1

2. Give a unique name to your project on OpenShift. (e.g.: Nodejs-setup). The fields “Display Name” and “Description” are optional.

Build a new app2

3. Browse through the developer catalog. Click on JavaScript and select Node.js example as a quickstart template.

Build a new app3

 

4. Name the resource that will be created by this application and the GitHub URL that was forked. Select the checkbox “create route” to access the application publicly.

Build a new app4
5. Click on ‘Create’ to deploy your application.


6. Check the status of the application by clicking the status and selecting the nodejs project.

Build a new app5

 

7.Click on the location tab to view the nodejs welcome page.

Build a new app6
8. This confirms that you have successfully deployed a nodejs app on OpenShift.

Build a new app7

 

Configure Continuous Integration (CI)

Now we will implement a CI workflow so that a rebuild of the application will get triggered when you push any changes to the GitHub repository. To accomplish this, we have to configure GitHub webhook URL from the application into GitHub repository using the following steps.

1. In the OpenShift Online web console:

a.    Select the nodejs project containing your application.

b.    Navigate through the Builds section , the click the name of your Node.js application.

c.    From the configuration tab, click on the box next to GitHub Webhook URL to copy your GitHub Webhook.

2. Next, add the webhook to the GitHub repository:

a.   In GitHub, click ’Add Webhook’ in the GitHub Webhook settings. Paste the payload URL into the Payload URL field. Ensure ‘Content’ type field is set to ’application/json’, instead of the default ‘application/x-www-form-urlencoded’. Then, click ‘Add Webhook’ to finish adding the webhook to your project:

ci1

b.   GitHub now attempts to ping the OpenShift Online server to ensure that the communication is successful. If it is correctly configured, you will see a green check mark next to your new webhook URL in GitHub.

ci2

3. Finally, if you push a code change to your forked repository, the nodejs application on OpenShift will be rebuilt automatically.

ci3

 

Building a Code change

Now it is time to push the modified code to the application.

1.  On your local desktop, use an editor to modify the GitHub code for the file (nodejs-ex/views/index.html)

2.  Make some changes that will be visible from your application. For instance, change the title on line 6.

Code change 1:
3. Commit the changes to GitHub and push the changes to master.

Screen Shot 2019-10-02 at 12.45.26 PM

4. If your webhooks are configured correctly, your OpenShift project will rebuild and deploy itself. To view the changes, open the web browser.

Scaling on Demand

To meet the demands of increased traffic volume, you can add additional pods to your Node.js service.

  1. In the OpenShift dashboard, view the overview page for your project. Click the up-arrow button under the Nodejs service to add an additional replica of your application.

Scale1

The Nodejs quickstart is configured to use 512 MB of memory per pod. You can check your quota usage in the web console:

  1. For the web console GUI, navigate to the project containing your application.
  2. Click on settings tab and scroll to the section titled Quota compute-resources to view usage:

Scale2

Conclusion

In this blog, we have seen how it easy it is to build, deploy and scale a Nodejs application using a Red Hat OpenShift. But this is probably just the first part of your application lifecycle journey. There is much more required. In the next installment, we'll go deep to show how Rafay and OpenShift work together.

The Rafay platform works seamlessly with OpenShift to deliver SaaS-based lifecycle management capabilities. The platform automates the repetitive work devops teams carry out to keep Kubernetes environments up and running in OpenShift and other environments. Our users love the product and continue to help us make it better. If you’d like to see a demo, feel free to get in touch or simply contact us at info@rafay.co.

Posted by Team Rafay