How to deploy full-stack JavaScript applications in OpenShift

Red Hat OpenShift is a Kubernetes distribution that makes it easy to deploy and scale applications in the cloud. In this hands-on learning path, created by Don Schenck, you will learn how to deploy a full-stack JavaScript application in an OpenShift cluster.

Access the Developer Sandbox

OpenShift has built-in database templates for Postgres, MariaDB, and MySQL. An ephemeral instance uses no disk space, making it an easy way to test before committing to the final solution.

Prerequisites:

In this lesson, you will:

  • Run one opinionated command to instantiate a Postgres database.

Get a list of templates

OpenShift has scores of built-in templates. To get a list of them, run the following command:

oc get templates -n openshift

You will see a lot of templates. The one to be used is titled postgresql-ephemeral. If you locate it in the list, you’ll see a short description.

Get information about the postgresql-ephemeral template

When the template is used, several parameter values will be needed. To see specifics, run the following command:

oc get template -n openshift  postgresql-ephemeral -o json

The following parameters and values will be used:

  • DATABASE_SERVICE_NAME=shorties
  • POSTGRESQL_USER=shorties
  • POSTGRESQL_PASSWORD=shorties
  • POSTGRESQL_DATABASE=urls

Create the database

With the parameter values listed, create the database instance by running the following command:

oc new-app --template=postgresql-ephemeral --param DATABASE_SERVICE_NAME=shorties --param POSTGRESQL_USER=shorties --param POSTGRESQL_PASSWORD=shorties --param POSTGRESQL_DATABASE=urls

Note that a route (i.e., external URL) to this is not needed. This is because only other services inside of our OpenShift cluster will be granted access to it. The only thing your services need to know is the service name, shorties. You don’t need a URL, nor do you need an IP address and port. This feature of Kubernetes that allows you to access a service by name alone is known as "service discovery".

Wrapping up

You now have a front-end website and a database. They will be connected by the two remaining backend services yet to be implemented: urlshortener-back and urlshortener-redirector.

Previous resource
Run an application locally then build a container for the front end and deploy it to OpenShift
Next resource
Deploy the back end and connect it to the database and front end