{{announcement.body}}
{{announcement.title}}

CLI Tool for Developers: Odo

DZone 's Guide to

CLI Tool for Developers: Odo

This article explains the rudimentary concepts about odo which is a developer-focused CLI tool for OpenShift and Kubernetes.

· Open Source Zone ·
Free Resource

Overview

Odo is an open-source project. Odo Client as the name signifies, it is completely client-based. It helps developers to write, build, and deploy applications on OpenShift and Kubernetes.

Hers is Interactive learning if new to OpenShift. Using the Odo command-line tool you can build and deploy applications on OpenShift and Kubernetes. Odo reduces the cognitive load as compared to oc client which is more operations-focused and requires a deep-understanding of Kubernetes and OpenShift concepts.

Requirements

  • Requires at least OpenShift v3.10.0, and Container Development Kit or Red Hat CodeReady Containers for OpenShift 4 for local clusters.
  • Minikube is a tool that makes it easy to run Kubernetes locally. It just requires few Installation steps to run a single-node Kubernetes cluster inside a Virtual Machine on your laptop.
  • No servers are required for its use, Odo runs entirely on a local client and supports macOS, Windows, and Linux

Supported Languages

At present odo supports Java and Node.JS  languages/framework.

To list the available components and associated container images for your cluster:

  • Log in to the cluster with odo:

$ odo login -u developer -p developer

  • List the available odo supported and unsupported components and corresponding container images:

    Java
     




    xxxxxxxxxx
    1
    15


     
    1
    [quicklab@master-1 ~]$ odo catalog list components
    2
    Odo OpenShift Components:
    3
    NAME              PROJECT       TAGS                        SUPPORTED
    4
    java              openshift     11,8,latest                 YES
    5
    nodejs            openshift     10-SCL,8,8-RHOAR,latest     YES
    6
    dotnet            openshift     2.1,2.2,3.0,latest          NO
    7
    golang            openshift     1.11.5,latest               NO
    8
    httpd             openshift     2.4,latest                  NO
    9
    modern-webapp     openshift     10.x,latest                 NO
    10
    nginx             openshift     1.10,1.12,latest            NO
    11
    perl              openshift     5.24,5.26,latest            NO
    12
    php               openshift     7.0,7.1,7.2,latest          NO
    13
    python            openshift     2.7,3.6,latest              NO
    14
    ruby              openshift     2.4,2.5,latest              NO
    15
     
                


    The TAGS column represents the available image versions.

Odo also supports IDE pl.ugins such as VS Code Openshift Connector which is a VS code extension that allows users to manages applications concerning the OpenShift instance which is running.

Now let's brief on how you can develop and deploy a single component application using a handful of commands without having a deep knowledge of the OpenShift cluster platform.

Terminologies:

  • Project
    A project is your source code, tests, and libraries organized in a separate single unit.

  • Application
    An application is a program designed for end-users. An application consists of multiple microservices or components that work individually to build the entire application. Examples of applications: a video game, a media player, a web browser.

  • Component
    A component is a set of Kubernetes resources that host code or data. Each component can be run and deployed separately. Examples of components: Node.js, Perl, PHP, Python, Ruby.

  • Service
    A service is a software that your component links to or depends on. Examples of services: MariaDB, Jenkins, MySQL. In odo, services are provisioned from the OpenShift Service Catalog and must be enabled within your cluster.

Binary Installation

On Linux:

Java
 




x


 
1
# curl -L https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-amd64 -o /usr/local/bin/odo
2
# chmod +x /usr/local/bin/odo



Deploy and Connect a Database to a Node-js Application

Create a project to keep your source code, tests, and libraries organized in a separate single unit.

  • Log in to an OpenShift cluster:

$ odo login -u developer -p developer

  • Create a project:

    Java
     




    xxxxxxxxxx
    1


     
    1
    $ odo project create nodejsproject
    2
       Project 'nodejsproject' is ready for use
    3
       New project created and now using project: nodejsproject
    4
     
                


  • Creating a Node.js application with odo

To create a Node.js component, download the Node.js application and push the source code to your cluster with odo.

  • Create a directory for your components:

    $ mkdir component;cd component

  • Download the example Node.js application:

    Java
     




    xxxxxxxxxx
    1


     
    1
     git clone https://github.com/openshift/nodejs-ex
    2
    Cloning into 'nodejs-ex'...
    3
    remote: Enumerating objects: 647, done.
    4
    remote: Total 647 (delta 0), reused 0 (delta 0), pack-reused 647
    5
    Receiving objects: 100% (647/647), 257.70 KiB | 2.39 MiB/s, done.
    6
    Resolving deltas: 100% (249/249), done.
    7
     
                


  • Change the current directory to the directory with your application:

$ cd <nodejs-ex>

  • Add a component of the type Node.js to your application:

    Java
     




    xxxxxxxxxx
    1


     
    1
    odo create nodejs
    2
    Validation
    3
       Validating component [17ms]
    4
     
                
    \
  • Push the initial source code to the component:

    Java
     




    xxxxxxxxxx
    1
    18


     
    1
     
                
    2
    $ odo push
    3
    Validation
    4
       Checking component [21ms]
    5
     
                
    6
    Configuration changes
    7
       Initializing component
    8
       Creating component [170ms]
    9
     
                
    10
    Applying URL changes
    11
       URLs are synced with the cluster, no changes are required.
    12
     
                
    13
    Pushing to component nodejs-nodejs-ex-uelr of type local
    14
       Checking files for pushing [1ms]
    15
       Waiting for component to start [1m]
    16
       Syncing files to the component [7s]
    17
       Building component [32s]
    18
       Changes successfully pushed to component


    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.

    Java
     




    xxxxxxxxxx
    1


    1
    $ odo url list
    2
    Found the following URLs for component nodejs-nodejs-ex-uelr in application app:
    3
    NAME                           STATE      URL                                                                                             PORT     SECURE
    4
    nodejs-nodejs-ex-uelr-8080     Pushed     http://nodejs-nodejs-ex-uelr-8080-app-nodejsproject.apps.test11.lab.upshift.rdu2.redhat.com     8080     false
    5
     
                


  • List the URLs to check the desired URL for the component.

$ odo url list

  • View your deployed application using the generated URL.

$ curl <URL>

Connect the Deployed Application to Services

Use odo in interactive mode to create services.  The Template Service Broker is not installed by default in OpenShift Container Platform 4. It can be installed using the web console. Follow the steps Install Template Service Broker using Console.

  • Java
     




    x


    1
     
                
    2
     odo service create
    3
    ? Which kind of service do you wish to create database
    4
    ? Which database service class should we use mongodb-persistent
    5
    ? Enter a value for string property DATABASE_SERVICE_NAME (Database Service Name): mongodb
    6
    ? Enter a value for string property MEMORY_LIMIT (Memory Limit): 512Mi
    7
    ? Enter a value for string property MONGODB_DATABASE (MongoDB Database Name): sampledb
    8
    ? Enter a value for string property MONGODB_VERSION (Version of MongoDB Image): 3.2
    9
    ? Enter a value for string property VOLUME_CAPACITY (Volume Capacity): 1Gi
    10
    ? Provide values for non-required properties No
    11
    ? How should we name your service  mongodb-persistent
    12
    ? Output the non-interactive version of the selected options No
    13
    ? Wait for the service to be ready No
    14
    Deploying service mongo-persistent of type: mongodb-persistent
    15
       Service 'mongodb-persistent' was created
    16
     
                
    17
    Progress of the provisioning will not be reported and might take a long time
    18
    You can see the current status by executing 'odo service list'
    19
    Optionally, link mongodb-persistent to your component by running: 'odo link <component-name>'



Now link the service to the nodejs-ex app using odo link command

Java
 




xxxxxxxxxx
1


 
1
odo link mongodb-persistent
2
   Service mongodb-persistent has been successfully linked from the component nodejs-nodejs-ex-uelr
3
    


Topics:
cli, devops, kubernetes, nodejs, odo, openshift

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}