This document walks you through the development and deployment of a Node.js application to an OpenShift cluster using
odo. It guides you on how to push new changes to your application and on other useful features of
Developing and deploying an application to an OpenShift cluster
To develop and deploy a Node.js application to an OpenShift cluster using
Log into an OpenShift cluster:
If you lack a local development cluster, we recommend using Minishift to deploy a development OpenShift cluster.
If you do not use Minishift,
odoautomatically works with any OpenShift cluster you are currently logged into. To log into the OpenShift cluster run:
$ odo login -u developer -p developer
An application is an umbrella that comprises of all the components (microservices) you build. Create a component as follows:
Download the sample application and change directory to the location of the application:
$ git clone https://github.com/openshift/nodejs-ex $ cd nodejs-ex
Add a component of the type nodejs to the application:
$ odo create nodejsNote
By default, the latest image is used. You can also explicitly supply an image version by using
odo create openshift/nodejs:8.
Push the initial source code to the component:
$ odo push
Your component is now deployed to OpenShift.
Create a URL and add an entry in the local configuration file as follows:
$ odo url create --port 8080
Push the changes. This creates a URL on the cluster.
$ odo push
List the URLs to check the desired URL for the component.
$ odo url list
View your deployed application using the generated URL.
$ curl <URL>
Edit your code and push the changes to the component:
Edit one of the layout files within the Node.js directory.
$ vim views/index.html
Push the changes:
$ odo push
Refresh your application in the browser to see the changes.
After each change, you can update your component using:
Adding storage to the component
odo enables you to persist data between restarts by making it easy to add storage to your component as follows:
$ odo storage create nodestorage --path=/opt/app-root/src/storage/ --size=1Gi
This adds storage to your component with an allocated size of 1 Gb.
Using command completion
odo provides smart completion of command parameters based on user input. For this to work,
odo needs to integrate with the executing shell.
To install command completion automatically, run
odo --completeand press
ywhen asked to install the completion hook.
To install the completion hook manually add
complete -o nospace -C <full path to your odo binary> odoto your shell configuration file (e.g.
To disable completion, run
After any modification to your shell configuration file, you will need to
source it or restart your shell.
.odoignore file in the root directory of your application is used to ignore a list of files/patterns. This applies to both
odo push and
.odoignore file does not exist, the
.gitignore file is used instead for ignoring specific files and folders.
For example, to ignore
.git files, any files with the
.js extension, and the folder
tests, add the following to either the
.odoignore or the
.git *.js /tests
.odoignore file allows any glob expressions to be used, for example you can use the following:
Using Service Catalog with
If you use Minishift, you require version 1.22 or above.
In order to use the Service Catalog it must be enabled within your OpenShift cluster.
Start an OpenShift cluster, version 3.10 and above.
Enable the Service Catalog:
$ MINISHIFT_ENABLE_EXPERIMENTAL=y minishift start --extra-clusterup-flags "--enable=*,service-catalog,automation-service-broker"
After you enable or start
To list the services, use:
$ odo catalog list services
To list service catalog related operations, use:
$ odo service <verb> <servicename>
Adding a custom builder
The following example demonstrates the successful import and use of the redhat-openjdk-18 image:
oc binary is installed and present on the
Import the image into OpenShift:
$ oc import-image openjdk18 --from=registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift --confirm
Tag the image to make it accessible to
$ oc annotate istag/openjdk18:latest tags=builder
Deploy it with
$ odo create openjdk18 --git https://github.com/openshift-evangelists/Wild-West-Backend