Developing NodeJS microservice for an OpenShift Cluster — Part III

Nagesh Subrahmanyam
Nov 4 · 6 min read

Abstract

This article in the series describes the demo of OpenShift customers with screen-shots of the web console. This article might simplify the starting up of the demo. For the CLI version, take a look at Part I and Part II.

This demo will cover the development and deployment of a NodeJS microservice for an OpenShift cluster.

Here is an index of the articles:

  1. Part I — Developing NodeJS microservice for an OpenShift Cluster — Part I — Project description
  2. Part II — Developing NodeJS microservice for an OpenShift Cluster — Part II — OpenShift artifacts creation with CLI and NodeJS considerations
  3. Part III — Developing NodeJS microservice for an OpenShift Cluster — Part III (this article) — OpenShift artifacts creation with web console and NodeJS considerations

Pre-requisites

You have a working minishift cluster (You may install minishift with instructions from here.) and can login to the console as a developer. The login is normally done using IP address from minishift ip command, user name developer and password as any string.

Steps

The following steps will be executed for a successful installation of this demo.

  1. Project set-up
  2. Service and End-point set-up for Redis service
  3. Configuration Map for environment variables
  4. Application with GitHub repository
  5. Application overview
  6. Exposing the application service with a route
  7. Modified deployment configuration to refer the configuration map

Project set-up

From the landing page, create a new project by clicking on Create Project.

Landing Page

Fill in the details as shown below and click Create. Note that, the name custdemo will serve as the name space of this project.

Create a new project

Redis service and end-point

I am yet to figure out how to create the service and end-point for Redis external instance from the web console. Until then, YAML and CLI is the only option.

Paste the contents below into a file openshift-demo-service.yaml.

Redis service definition

Paste the contents below into a file openshift-demo-endpoint.yaml.

Redis endpoint definition

Notes:

  1. The name (line 4) should be same as the name of the service in the service definition YAML file.
  2. The ip address should be the one for Redis external database.
  3. The name of ports (line 10) should be same as the name in the service definition YAML file.

Once the YAML files are prepared, run the following commands to create them:

On the web console, the service can be looked up from the left navigation bar, Applications -> Services. The Endpoint can be looked up at Resources -> Other Resources and selecting Endpoints from the drop down.

Configuration map

To create a configuration, go to the left navigation bar, click on Resources -> Config Maps and click on Create Config Map. Enter details as shown below.

Configuration Map definition

Application

To create a new application, go to the catalog either from the home page or from the last icon on the left navigation bar. In the catalog, locate NodeJS and click on it. Then, click Next and add https://github.com/nsubrahm/openshift-demo-customers GitHub URL for the Git Repository as shown below. Click Create.

Creating an application

Application Overview

After clicking create, go to the Overview page to see the results of creating this application. It should look something like this below.

  1. A Deployment Configuration will be seen with the status of the pod.
  2. Clicking on this deployment configuration will show three associated items: Builds, Networking and Containers.
  3. The Builds section will show the status of build. OpenShift will automatically detect the language and initiate a S2I (Source to Image) build strategy. See here for more details. A successful build will create an image that can be located from the left navigation bar as Builds -> Images.
  4. The Networking section shows both the service that can be resolved inside the cluster only.
  5. The Containers section shows the status of the container that was triggered as part of the deployment configuration. The trigger will use the image created from the build configuration. The color of the annulus will turn into blue if the launch was successful; else, it will be red. The grey color denotes that the container is still being created. The number 1 denotes the count of instances that are running.

Exposing the service with a route

The Service openshift-demo-customers (as seen in the screenshot above) is visible only within the customer. It has to be exposed with a route so that it can be accessed from outside the cluster also. To do this, either click on Create Route visible to the right of the service name in the screenshot above. Or, from the left navigation bar, go to Applications -> Routes and click Create Route. Enter the name as custdemo.apis as shown below and leave rest unchanged. Just ensure that, the name of service matches the one created above openshift-demo-customers.

Exposing the application service with a route

Click Create and the result should look like this. Note the value under Hostname — that is the value to be used from Postman, etc. to access the service from outside the cluster.

Host name of the route to be used externally

Deployment Configuration

After a while, you will notice that the launch has failed. This is expected because the configuration map is not associated with the deployment configuration. Recall that, the NodeJS application refers to environment variables that are injected into the containers from the key in the configuration map. To associate the configuration map with the deployment configuration, go to Applications on left navigation bar and click on Deployments. Click on custdemo to open the deployment configuration and click on Environment tab to set the environment variables as shown below.

Adding environment variables in deployment configuration

Click on Add Value from Config Map or Secret to see a row for entering details as shown below. Click Save.

Adding environment variables from configuration map into deployment configuration

Since the deployment configuration is now changed, a deployment is automatically triggered. This deployment completes successfully — note the blue color of the annulus for the pod.

Successful deployment after adding environment variables

Click on the pod icon and click on the Logs tab to see results of the successful launch.

Logs of successful launch

Testing

To test this deployment, use the host name of the Route in the Postman scripts from here — https://github.com/nsubrahm/openshift-demo-postman

Nagesh Subrahmanyam

Written by

Software Architect — converts voice of customer to realistic, monetized products.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade