Scaffold and Deploy a Scalable Web Application to OpenShift

This post is an excerpt from a solution tutorial that walks you through on how to scaffold a web application, run it locally in a container, push the scaffolded code to a private Git repository and then deploy it to a Red Hat OpenShift on IBM Cloud cluster. Additionally, you will learn how expose the app on an OpenShift route, bind a custom domain, monitor the health of the environment, and scale the application.

Vidyasagar Machupalli
Aug 26 · 5 min read

With the Red Hat OpenShift on IBM Cloud, you can create IBM Cloud Kubernetes Service clusters with worker nodes that come installed with the Red Hat OpenShift on IBM Cloud Container Platform orchestration software. You get all the advantages of managed IBM Cloud Kubernetes Service for your cluster infrastructure environment, while using the OpenShift tooling and catalog that runs on Red Hat Enterprise Linux for your app deployments.

For developers looking to kickstart their projects, the IBM Cloud Developer Tools CLI enables rapid application development and deployment by generating template applications that you can run immediately or customize as the starter for your own solutions.


Objectives

  • Scaffold a starter application.
  • Deploy the application to the Red Hat OpenShift on IBM Cloud cluster.
  • Bind a custom domain.
  • Monitor the logs and health of the cluster.
  • Scale OpenShift pods.

Services used

This tutorial uses the following runtimes and services:

This tutorial may incur costs. Use the Pricing Calculator to generate a cost estimate based on your projected usage.


Architecture

  1. A developer generates a starter application with IBM Cloud Developer Tools.
  2. The dev adds the generated starter kit code to a private Git repository on IBM Cloud
  3. A Docker container image is build from the code.
  4. The image is pushed to a namespace in IBM Cloud Container Registry.
  5. The application is deployed to an OpenShift cluster by pulling the image.
  6. Users access the application.

Before you begin

  1. Install IBM Cloud Developer Tools — Script to install docker, kubectl, ibmcloud cli and required plug-ins like dev, ks, cr …
  2. Install the OpenShift Origin (oc) CLI
  3. Configure your access to IBM Cloud Git to be able to commit source code to a private Git repository.
  4. Use these instructions to generate a new SSH key pair if you don’t have one.
  5. And add your SSH public key to your Git settings.
  6. Set up the IBM Cloud Container Registry CLI and your registry namespace

Create an OpenShift cluster

With Red Hat OpenShift on IBM Cloud, you have a fast and secure way to containerize and deploy enterprise workloads in OpenShift clusters. OpenShift clusters build on Kubernetes container orchestration that offers consistency and flexibility for your development lifecycle operations.

In this section, you will provision a Red Hat OpenShift on IBM Cloud cluster with two worker nodes.

  1. Create an OpenShift cluster from the IBM Cloud™ catalog.
  2. Set Cluster name to myopenshiftcluster.
  3. Select a Resource group and choose a Geography.
  4. Under Location,
  • Select a Metro.
  • Choose a single Worker zone by unchecking the other worker zones.
  • Select Public endpoint only as your Master service endpoint.

5. Under Default worker pool,

  • Choose OpenShift 3.11 as your cluster type and version.
  • Select 4 Cores 16GB RAM as the flavor for Worker nodes.
  • Leave Encrypt local disk checked and select 2 Worker nodes for this tutorial.

6. Review Infrastructure permissions checker to verify the required permissions

7. Click Create cluster to provision an OpenShift cluster.

Configure CLI

In this step, you’ll configure oc to point to your newly created cluster. The OpenShift Container Platform CLI exposes commands for managing your applications, as well as lower level tools to interact with each component of your system. The CLI is available using the oc command.

  1. When the cluster is ready, click on the Access tab under the cluster name.
  2. Under After your cluster provisions, gain access section, click on oauth token request page link and follow instructions to log into your cluster on a terminal.
  3. Once logged-in using the oc login command, run the below command to see all the namespaces in your cluster
oc get ns

Generate a starter kit

The ibmcloud dev tooling greatly cuts down on development time by generating application starters with all the necessary boilerplate, build and configuration code so that you can start coding business logic faster.

Using ibmcloud dev plugin

  1. On a terminal, start the ibmcloud dev wizard by running the below command
ibmcloud dev create
  1. You may be asked to target an organization and a space, follow the instructions on the CLI
  2. Select Backend Service / Web App then Node and select Node.js Web App with Express.js to create a Node starter.
  3. Enter a name for your application.
  4. Select a resource group same as the cluster to deploy this application.
  5. Do not add additional services.
  6. Do not add a DevOps toolchain, select manual deployment.

This generates a starter application complete with the code and all the necessary configuration files for local development and deployment to cloud on Cloud Foundry or Kubernetes Service.

Run the application locally

You can build and run the application as you normally would using npm for node development. You can also build a docker image and run the application in a container to ensure consistent execution locally and on the cloud. Use the following steps to build your docker image.

  1. Ensure your local Docker engine is started.
docker ps

2. Change to the directory of the generated project.

cd <project name>

3. Build the application.This might take a few minutes to run as all the application dependencies are downloaded and a Docker image, which contains your application and all the required environment, is built.

ibmcloud dev build

4. Run the container.

ibmcloud dev run

5. This uses your local Docker engine to run the docker image that you built in the previous step.

6. After your container starts, go to http://localhost:3000/

What’s next?

Push the code to a Private IBM Cloud Git repo

Deploy the application to an OpenShift cluster

Use your own custom domain

Monitor the app

Scale the app

vmacwrites

Tech writings by Vidyasagar Machupalli

Vidyasagar Machupalli

Written by

Developer, IBMer, Speaker, Blogger, Teetotaller, Geek & many more…

vmacwrites

Tech writings by Vidyasagar Machupalli

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