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.
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.
- 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.
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.
- A developer generates a starter application with IBM Cloud Developer Tools.
- The dev adds the generated starter kit code to a private Git repository on IBM Cloud
- A Docker container image is build from the code.
- The image is pushed to a namespace in IBM Cloud Container Registry.
- The application is deployed to an OpenShift cluster by pulling the image.
- Users access the application.
Before you begin
- Install IBM Cloud Developer Tools — Script to install docker, kubectl, ibmcloud cli and required plug-ins like dev, ks, cr …
- Install the OpenShift Origin (oc) CLI
- Configure your access to IBM Cloud Git to be able to commit source code to a private Git repository.
- Use these instructions to generate a new SSH key pair if you don’t have one.
- And add your SSH public key to your Git settings.
- 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.
- Create an OpenShift cluster from the IBM Cloud™ catalog.
- Set Cluster name to myopenshiftcluster.
- Select a Resource group and choose a Geography.
- 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.
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
- When the cluster is ready, click on the Access tab under the cluster name.
- 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.
- Once logged-in using the
oc logincommand, run the below command to see all the namespaces in your cluster
oc get ns
Generate a starter kit
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
- On a terminal, start the
ibmcloud devwizard by running the below command
ibmcloud dev create
- You may be asked to target an organization and a space, follow the instructions on the CLI
Backend Service / Web Appthen
Node.js Web App with Express.jsto create a Node starter.
- Enter a name for your application.
- Select a resource group same as the cluster to deploy this application.
- Do not add additional services.
- 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.
- Ensure your local Docker engine is started.
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