Odo with Kubernetes

Binding is the task of finding a backing service and connecting it to an application, such as a database. There are several ways to bind applications to cloud services in Kubernetes and Red Hat OpenShift. The odo command-line interface (CLI) consolidates steps that developers normally have to perform manually, and abstracts away Kubernetes and OpenShift background concepts.

With odo, you can concentrate on creating applications instead of administering the cluster. The odo tool automates deployment configurations, build configurations, service routes, and other Kubernetes and OpenShift elements.

The Service Binding Operator, employed by odo, makes the application developer's life a lot easier by providing a consistent and declarative Service Binding method.

This two-part series demonstrates how to use odo to create an application and a database service, bind the application to the database using the Service Binding Operator, and get access to the application's REST API. This article prepares the environment with the necessary tools. In part 2, Implementation of RestAPI application with MongoDB using SBO, we will install MongoDB and the application, and bind them together.

A REST application example

We will use a REST application written in Go as an example here. The application connects to a MongoDB database using the Service Binding Operator and allows you to manage entries in the database. Data consists of place names and descriptions. The REST API's endpoints allow you to add details to the MongoDB instance and perform create, read, update, and delete (CRUD) operations.

When you request a binding, the Service Binding Operator looks at the data stored within the custom resource (CR) and its corresponding custom resource definition (CRD) inside the service. This data contains the parameters required to bind the application to the service. The Service Binding Operator then projects this binding data into the application's workload resources as environment variables or files. To learn more about the Service Binding Operator and its integration with other products, refer to the Service Binding documentation.


To run and interact with the application, you must complete the following procedures successfully:

  1. Install Go and odo packages
  2. Set up an OpenShift cluster with administrator access
  3. Install the Percona Distribution for MongoDB Operator
  4. Install the Service Binding Operator

We will use the following versions of these tools to showcase the application:

  • Go 1.18.7
  • odo v3.0.0
  • OpenShift 4.11
  • Percona Distribution for MongoDB Operator 1.13.0, provided by Percona

The following steps provide instructions for each prerequisite.

Step 1: Install Go and odo packages

Install Go following the official guidelines.
The odo installation process is as simple as downloading the binary for your OS/ARCH and placing it into a folder referenced by your PATH environment variable. In the following you find the installation procedure for Linux/amd64 and odo-v3.0.0. For a different OS or architecture, check the odo Installation page.
  1. Download the latest release from the mirror site

    $ curl -L https://developers.redhat.com/content-gateway/rest/mirror/pub/openshift-v4/clients/odo/v3.0.0/odo-linux-amd64 -o odo
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
      0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
      0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
    100 66.7M  100 66.7M    0     0  3261k      0  0:00:20  0:00:20 --:--:-- 3729k
  2. Install odo, you might have to provide your password for root access:

    $ sudo install -o root -g root -m 0755 odo /usr/local/bin/odo
    [sudo] password for user:

    If you are not allowed to use sudo or you prefer a rootless installation, you can install the odo tool to a local folder, like for example ~/.local/bin, and configure your shell:

    $ mkdir -p ~/.local/bin
    $ mv odo ~/.local/bin
    $ export PATH=${HOME}/.local/bin/odo:${PATH}
  3. Verify that odo is installed:

    $ odo version
    odo v3.0.0 (8694f1946)

Step 2: Set up an OpenShift cluster

There are several ways to use OpenShift, like using crc or running a managed cluster. You can find more details in the getting started page. To complete the demo, please ensure to have a cluster with at least 16GB of memory.
After you install and log into your own cluster, or log into a managed cluster in the cloud, create a project with the following command:
$ odo create project mongodb-restapi
 ✓  Project "mongodb-restapi" is ready for use
 ✓  New project created and now using project: mongodb-restapi

Step 3: Install the Percona Distribution for MongoDB Operator

We are not installing from OperatorHub because the installation should be done to our specific mongodb-restapi OpenShift namespace.

Follow these two steps:

  1. Install the Percona Distribution for MongoDB Operator:

    $ oc create -f https://raw.githubusercontent.com/redhat-developer/openshift-app-services-demos/main/samples/sbo/restapi-mongodb-odo/operators/mongodb-percona-distribution.yaml
    subscription.operators.coreos.com/percona-server-mongodb-operator created
    operatorgroup.operators.coreos.com/operatorgroup created
  2. Verify that you have successfully installed the Percona Distribution for MongoDB Operator. Figure 6 shows the output.
    $ oc get csv -n mongodb-restapi
    NAME                                 DISPLAY                                     VERSION   REPLACES   PHASE
    percona-server-mongodb-operator.v1   Percona Distribution for MongoDB Operator   1.13.0               Succeeded

Step 4: Install the Service Binding Operator

The Service Binding Operator is always installed in all namespaces. Here, we are not installing from the OperatorHub because we must install the Operator in a particular namespace named openshift-operators.

The following two steps will complete the process:

  1. Install the Service Binding Operator:

    $ oc create -f https://raw.githubusercontent.com/redhat-developer/openshift-app-services-demos/main/samples/sbo/restapi-mongodb-odo/operators/servicebinding-operator.yaml
    subscription.operators.coreos.com/my-service-binding-operator created
  2. Verify that the Service Binding Operator is successfully installed in your namespace:

    $ oc get csv -n mongodb-restapi
    NAME                                 DISPLAY                                     VERSION   REPLACES                          PHASE
    percona-server-mongodb-operator.v1   Percona Distribution for MongoDB Operator   1.13.0                                      Succeeded
    service-binding-operator.v1.3.0      Service Binding Operator                    1.3.0     service-binding-operator.v1.2.0   Succeeded


The installation and setup are now complete. In the next article, you will clone the application and create a database component for it. If you have questions, please comment below. We welcome your feedback.

Last updated: November 8, 2023