odo allows you to easily create and deploy applications on OpenShift Container Platform clusters.

Prerequisites
  • odo is installed.

  • You have a running OpenShift Container Platform cluster. Developers can use CodeReady Containers (CRC) to deploy a local OpenShift Container Platform cluster quickly.

Creating a project

Procedure
  1. Log in to an OpenShift Container Platform cluster:

    $ odo login -u developer -p developer
  2. Create a new directory for your components:

    $ mkdir my_components
    $ cd my_components
  3. Download the example Node.js application:

    $ git clone https://github.com/openshift/nodejs-ex
  4. Create a new project:

    $ odo project create myproject
     ✓  Project 'myproject' is ready for use
     ✓  New project created and now using project : myproject

Creating a Node.js application with odo

Procedure
  1. Change the current directory to the front-end directory:

    $ cd <directory-name>
  2. Add a component of the type Node.js to your application:

    $ odo create nodejs
    By default, the latest image is used. You can also explicitly supply an image version by using odo create openshift/nodejs:8.
  3. Push the initial source code to the component:

    $ odo push

    Your component is now deployed to OpenShift Container Platform.

  4. Create a URL and add an entry in the local configuration file as follows:

    $ odo url create --port 8080
  5. Push the changes. This creates a URL on the cluster.

    $ odo push
  6. List the URLs to check the desired URL for the component.

    $ odo url list
  7. View your deployed application using the generated URL.

    $ curl <URL>

Modifying your application code

You can modify your application code and have the changes applied to your application on OpenShift Container Platform.

  1. Edit one of the layout files within the Node.js directory with your preferred text editor.

  2. Update your component:

    $ odo push
  3. Refresh your application in the browser to see the changes.

Adding storage to the application components

Persistent storage keeps data available between restarts of odo. The odo storage command allows you to add storage to your components:

$ 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.

Adding a custom builder to specify a build image

OpenShift Container Platform enables you to add a custom image to bridge the gap between the creation of custom images.

The following example demonstrates the successful import and use of the redhat-openjdk-18 image:

Prerequisites
  • The OpenShift CLI (oc) is installed.

Procedure
  1. Import the image into OpenShift Container Platform:

    $ oc import-image openjdk18 --from=registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift --confirm
  2. Tag the image to make it accessible to odo:

    $ oc annotate istag/openjdk18:latest tags=builder
  3. Deploy it with odo:

    $ odo create openjdk18 --git https://github.com/openshift-evangelists/Wild-West-Backend

Connecting your application to multiple services using OpenShift Service Catalog

The OpenShift service catalog is an implementation of the Open Service Broker API (OSB API) for Kubernetes. This allows you to connect applications deployed in OpenShift Container Platform to a variety of services.

Prerequisites
  • You have a running OpenShift Container Platform cluster.

  • The service catalog is installed and enabled on your cluster.

Procedure
  • To list the services, use:

    $ odo catalog list services
  • To use service catalog-related operations:

    $ odo service <verb> <servicename>

Sample applications

odo offers partial compatibility with any language or runtime listed within the OpenShift catalog of component types. For example:

NAME        PROJECT       TAGS
dotnet      openshift     2.0,latest
httpd       openshift     2.4,latest
java        openshift     8,latest
nginx       openshift     1.10,1.12,1.8,latest
nodejs      openshift     0.10,4,6,8,latest
perl        openshift     5.16,5.20,5.24,latest
php         openshift     5.5,5.6,7.0,7.1,latest
python      openshift     2.7,3.3,3.4,3.5,3.6,latest
ruby        openshift     2.0,2.2,2.3,2.4,latest
wildfly     openshift     10.0,10.1,8.1,9.0,latest

For odo 1.0 Java and Node.js are the officialy supported component types. Run odo catalog list components to verify the officially supported component types.

In order to access the component over the web, create a URL using odo url create.

Examples from Git repositories

httpd

This example helps build and serve static content using httpd on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the Apache HTTP Server container image repository.

$ odo create httpd --git https://github.com/openshift/httpd-ex.git

java

This example helps build and run fat JAR Java applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the Java S2I Builder image.

$ odo create java --git https://github.com/spring-projects/spring-petclinic.git

nodejs

Build and run Node.js applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the Node.js 8 container image.

$ odo create nodejs --git https://github.com/openshift/nodejs-ex.git

perl

This example helps build and run Perl applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the Perl 5.26 container image.

$ odo create perl --git https://github.com/openshift/dancer-ex.git

php

This example helps build and run PHP applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the PHP 7.1 Docker image.

$ odo create php --git https://github.com/openshift/cakephp-ex.git

python

This example helps build and run Python applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the Python 3.6 container image.

$ odo create python --git https://github.com/openshift/django-ex.git

ruby

This example helps build and run Ruby applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see Ruby 2.5 container image.

$ odo create ruby --git https://github.com/openshift/ruby-ex.git

wildfly

This example helps build and run WildFly applications on CentOS 7. For more information about using this builder image, including OpenShift Container Platform considerations, see the Wildfly - CentOS Docker images for OpenShift.

$ odo create wildfly --git https://github.com/openshift/openshift-jee-sample.git

Binary examples

java

Java can be used to deploy a binary artifact as follows:

$ git clone https://github.com/spring-projects/spring-petclinic.git
$ cd spring-petclinic
$ mvn package
$ odo create java test3 --binary target/*.jar
$ odo push

wildfly

WildFly can be used to deploy a binary application as follows:

$ git clone https://github.com/openshiftdemos/os-sample-java-web.git
$ cd os-sample-java-web
$ mvn package
$ cd ..
$ mkdir example && cd example
$ mv ../os-sample-java-web/target/ROOT.war example.war
$ odo create wildfly --binary example.war