2021 Call for Code Awards: Live from New York, with SNL’s Colin Jost! Learn more

Deploy Enterprise MongoDB using Helm charts on Red Hat OpenShift for IBM Power Systems

This tutorial is part of the Learning path: Deploying Red Hat OpenShift Container Platform 4.x on IBM Power Systems Virtual Servers.

Introduction

In this tutorial, we’ll show you how to deploy MongoDB using Helm charts on the Red Hat OpenShift Container Platform running on IBM Power Systems. For customers who use Kubernetes-based clusters to eliminate single point of failure, the Red Hat OpenShift Container Platform offers full control over their Kubernetes environment. And, IBM Power Systems is the preferred platform for running enterprise grade workloads, including those utilizing container platforms, such as OpenShift.

This tutorial provides an overview of the installation of a MongoDB-based Helm chart along with the steps to load the data set on Red Hat OpenShift Container platform running on IBM Power Systems. It also outlines the steps on how to interact with the data using a sample application.

Prerequisites

The infrastructure consists of controller nodes, worker nodes, and a helper (bastion) node along with a sample application. The setup includes OpenShift Container Platform for IBM Power (ppc64le) installed and configured on IBM Power Systems Virtual Server as per the instructions at https://developer.ibm.com/tutorials/install-ocp-on-power-vs/

For more information on prerequisites, configuration, and instructions to deploy a Helm chart on OpenShift Container Platform refer to the README.md file at: https://github.com/redhat-developer/redhat-helm-charts/blob/master/stable/ibm-mongodb-enterprise-helm/README.md

Estimated time

The approximate time taken to deploy the Enterprise MongoDB Helm chart on OpenShift Container Platform on Power, load the application data, and query is nearly 30 to 45 minutes.

What is a Helm chart?

Helm charts are Kubernetes YAML manifests combined into a single package that can be advertised to your Kubernetes clusters. Once packaged, installing a Helm chart into your cluster is as easy as running a single Helm installation, which really simplifies the deployment of containerized applications.

MongoDB Helm chart for IBM Power System is available at the Red Hat Developer GitHub: https://github.com/redhat-developer/redhat-helm-charts/tree/master/stable/ibm-mongodb-enterprise-helm

The Helm chart when deployed in the OpenShift Container Platform creates the following objects on the cluster:

  • Service (with the name, <release_name>-ibm-mongodb-enterprise-helm-service )
  • Deployment (with the name, <release_name>-ibm-mongodb-enterprise-helm-deployment)
  • Network policy (with the name, <release_name>-ibm-mongodb-enterprise-helm-network-policy)
  • Route (with the name, <release_name>-ibm-mongodb-enterprise-helm-route)

Note: Here, <release_name> refers to the name of the Helm chart passed during installation.

Steps

The process of installing a Helm chart in ppc64le is the same as in x86_64. Based on the underlying architecture (ppc64le or x86_64), Helm chart uses the Docker image specific to that architecture.

This section provides an overview of the installation of Helm chart along with the steps to load the data set. It also outlines the steps on how to interact with the data using a sample application.

Install the Helm chart

Perform the following steps to install the Helm chart and access the MongoDB pod.

  1. Create a clone of the GitHub repository on your server.

     $ cd $HOME/
     $ git clone https://github.com/redhat-developer/redhat-helm-charts
     $ cd redhat-helm-charts/stable/ibm-mongodb-enterprise-helm/
    
  2. Create a new project or namespace.

    $ oc new-project ibm -description="IBM ISDL" --display-name="ibm"
    $ oc project ibm
    
  3. Create a persistent volume (PV), which is required to provision storage for the application.

     $ oc create -f pv.yaml
    
  4. Update the following variables in the values.yaml file with the related values used during PV creation.

    database.adminuser, database.adminpassword, database.name_database, values.global.persistance.claims.storageClassName and values.global.persistence.claims.name

  5. Update the security context constraints (SCCs) in your namespace.

    $ oc adm policy add-scc-to-user anyuid -z default mongod
    
  6. Install the Helm chart.

    $ helm install test -f ./values.yaml ../ibm-mongodb-enterprise-helm/
    
  7. Check the status of the Helm chart and the MongoDB pod. Make sure that the pod is in the Running state.

     $ helm ls
     NAME    NAMESPACE  REVISION    UPDATED                                  STATUS     CHART                                APP VERSION
    
     test    harsha      1         2021-01-19 11:49:53.626581975 -0500 EST   deployed   ibm-mongodb-enterprise-helm-0.1.0     1.16.0
    
     $ oc get po
     NAME                                                            READY    STATUS    RESTARTS   AGE
     test-ibm-mongodb-enterprise-helm-deployment-7d77767cf8-mspj4    1/1       Running    0         3m37s
    

Load the data sets

This section outlines the steps to load listings and calendar collections available through the MongoDB sample data at https://docs.atlas.mongodb.com/sample-data/sample-airbnb/ supplied by AirBnB. Perform the following steps to load the data into the MongoDB pod.

  1. Download and then extract the listings and calendar collections on our bastion node.

    $ mkdir $PWD/data_airbnb
    $ wget http://data.insideairbnb.com/the-netherlands/north-holland/amsterdam/2021-02-08/data/listings.csv.gz
    $ wget http://data.insideairbnb.com/the-netherlands/north-holland/amsterdam/2021-02-08/data/calendar.csv.gz
    $ gzip -d listings.csv.gz
    $ gzip -d calendar.csv.gz
    
  2. Push the data to the pod using the rsync command. In this example, the data is copied to the /tmp/ directory of the pod.

    $ oc rsync data_airbnb <pod-name>:/tmp
    data_airbnb/calendar.csv
    data_airbnb/listings.csv
    
  3. Load the data to the MongoDB database running inside the container using the mongoimport utility provided by MongoDB.

    1. Run the rsh command to access the pod.

      $ oc rsh <pod-name>
      

      Alternatively, log in to the OpenShift Container Platform web console, select the pods from the workload menu and click the terminal to get a remote shell.

    2. Load the Calendar.csv collection.

      $ mongoimport --uri="mongodb://<Username>:<Password>@<IP Address:Port>/airbnb?authSource=admin" -c calendar --type csv --headerline --drop /tmp/data_airbnb/calendar.csv
      
      2021-04-12T09:04:07.639+0000    connected to: mongodb://[**REDACTED**]@0.0.0.0/airbnb?authSource=admin
      2021-04-12T09:04:07.640+0000    dropping: airbnb.calendar
      2021-04-12T09:04:10.640+0000    [........................] airbnb.calendar      3.05MB/276MB (1.1%)
      2021-04-12T09:04:13.639+0000    [........................] airbnb.calendar      5.08MB/276MB (1.8%)
      2021-04-12T09:04:16.639+0000    [........................] airbnb.calendar      8.42MB/276MB (3.0%)
      2021-04-12T09:04:19.639+0000    [#.......................] airbnb.calendar      12.9MB/276MB (4.7%)
      2021-04-12T09:04:22.639+0000    [#.......................] airbnb.calendar      17.4MB/276MB (6.3%)
      2021-04-12T09:04:25.639+0000    [#.......................] airbnb.calendar      21.9MB/276MB (7.9%)
      2021-04-12T09:04:28.639+0000    [##......................] airbnb.calendar      26.1MB/276MB (9.4%)
      2021-04-12T09:04:31.641+0000    [##......................] airbnb.calendar      30.7MB/276MB (11.1%)
      2021-04-12T09:04:34.639+0000    [###.....................] airbnb.calendar      35.3MB/276MB (12.8%)
      2021-04-12T09:04:37.639+0000    [###.....................] airbnb.calendar      39.8MB/276MB (14.4%)
      2021-04-12T09:04:40.639+0000    [###.....................] airbnb.calendar      44.0MB/276MB (15.9%)
      2021-04-12T09:04:43.639+0000    [####....................] airbnb.calendar      48.0MB/276MB (17.4%)
      2021-04-12T09:04:46.640+0000    [####....................] airbnb.calendar      52.4MB/276MB (19.0%)
      2021-04-12T09:04:49.640+0000    [####....................] airbnb.calendar      57.1MB/276MB (20.7%)
      2021-04-12T09:04:52.639+0000    [#####...................] airbnb.calendar      61.8MB/276MB (22.4%)
      2021-04-12T09:04:55.639+0000    [#####...................] airbnb.calendar      66.2MB/276MB (24.0%)
      2021-04-12T09:04:58.639+0000    [######..................] airbnb.calendar      70.5MB/276MB (25.5%)
      2021-04-12T09:05:01.639+0000    [######..................] airbnb.calendar      75.2MB/276MB (27.2%)
      2021-04-12T09:05:04.640+0000    [######..................] airbnb.calendar      80.1MB/276MB (29.0%)
      2021-04-12T09:05:07.640+0000    [#######.................] airbnb.calendar      84.8MB/276MB (30.7%)
      2021-04-12T09:05:10.639+0000    [#######.................] airbnb.calendar      89.0MB/276MB (32.2%)
      2021-04-12T09:05:13.639+0000    [#######.................] airbnb.calendar      92.0MB/276MB (33.3%)
      2021-04-12T09:05:16.640+0000    [########................] airbnb.calendar      96.3MB/276MB (34.9%)
      2021-04-12T09:05:19.639+0000    [########................] airbnb.calendar      101MB/276MB (36.6%)
      2021-04-12T09:05:22.639+0000    [#########...............] airbnb.calendar      106MB/276MB (38.3%)
      2021-04-12T09:05:25.639+0000    [#########...............] airbnb.calendar      110MB/276MB (40.0%)
      2021-04-12T09:05:28.640+0000    [#########...............] airbnb.calendar      113MB/276MB (40.8%)
      2021-04-12T09:05:31.639+0000    [##########..............] airbnb.calendar      117MB/276MB (42.5%)
      2021-04-12T09:05:34.639+0000    [##########..............] airbnb.calendar      122MB/276MB (44.1%)
      2021-04-12T09:05:37.639+0000    [##########..............] airbnb.calendar      126MB/276MB (45.8%)
      2021-04-12T09:05:40.640+0000    [###########.............] airbnb.calendar      131MB/276MB (47.3%)
      2021-04-12T09:05:43.641+0000    [###########.............] airbnb.calendar      134MB/276MB (48.7%)
      2021-04-12T09:05:46.639+0000    [############............] airbnb.calendar      139MB/276MB (50.3%)
      2021-04-12T09:05:49.639+0000    [############............] airbnb.calendar      144MB/276MB (52.0%)
      2021-04-12T09:05:52.639+0000    [############............] airbnb.calendar      148MB/276MB (53.7%)
      2021-04-12T09:05:55.639+0000    [#############...........] airbnb.calendar      153MB/276MB (55.3%)
      …..
      2021-04-12T09:06:07.644+0000    [##############..........] airbnb.calendar      170MB/276MB (61.7%)
      2021-04-12T09:07:07.639+0000    [######################..] airbnb.calendar      262MB/276MB (94.8%)
      2021-04-12T09:07:10.639+0000    [#######################.] airbnb.calendar      266MB/276MB (96.4%)
      ……. 
      2021-04-12T09:07:13.639+0000    [#######################.] airbnb.calendar      270MB/276MB (97.8%)
      2021-04-12T09:07:16.639+0000    [#######################.] airbnb.calendar      275MB/276MB (99.5%)
      2021-04-12T09:07:17.551+0000    [########################] airbnb.calendar      276MB/276MB (100.0%)
      2021-04-12T09:07:17.551+0000    6676319 document(s) imported successfully. 0 document(s) failed to import.
      
    3. Load the listings.csv collection.

      $ mongoimport --uri="mongodb://<UserName>:<Password>@<IP Address:Port>/airbnb?authSource=admin" -c listings --type csv --headerline --drop /tmp/data_airbnb/listings.csv
      2021-04-12T09:13:34.538+0000    connected to: mongodb://[**REDACTED**]@0.0.0.0/airbnb?authSource=admin
      2021-04-12T09:13:34.538+0000    dropping: airbnb.listings
      2021-04-12T09:13:37.538+0000    [##################......] airbnb.listings      31.7MB/40.6MB (78.1%)
      2021-04-12T09:13:38.533+0000    [########################] airbnb.listings      40.6MB/40.6MB (100.0%)
      2021-04-12T09:13:38.533+0000    18291 document(s) imported successfully. 0 document(s) failed to import.
      

Set up the client application

This section outlines the steps to configure a client application. The data from the MongoDB container can be queried and displayed either by a stand-alone or a dockerized application. This tutorial shows how a stand-alone Node.js application can query the data from the MongoDB pod.

  1. Download and install Node.js, using the following references:

    The Node.js application uses the MongoDB client to establish connectivity to the database. The application queries properties with the price range of USD 300 and would allow a maximum of 100 nights of stay.

  2. In this Node.js application, update the values in bold font.

    "mongodb://<Username>:<Password>@<IP_Address:Port>/airbnb?authSource=admin";

     $ cat app.js
     var http = require('http');
     var MongoClient = require('mongodb').MongoClient;
     var url = "mongodb://<Username>:<Password>@<IP Address:Port>/airbnb?authSource=admin";
     MongoClient.connect(url, function(err, client) {
     var db = client.db('airbnb');
     if (err) throw err;
     var query = { maximum_nights: 100,
                    price: '$300.00'
                   };
     db.collection("calendar").find(query).toArray(function(err, result) {
     if (err) throw err;
     console.log(result);
     client.close();
     });
     });
    
  3. Run the application to list the required properties.

    $ node app.js
    (node:1452264) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
    [ { _id: 6076da6c5706ebd01e1be6cf,
     listing_id: 432233,
     date: '2021-02-10',
     available: 'f',
     price: '$300.00',
     adjusted_price: '$300.00',
     minimum_nights: 2,
     maximum_nights: 100 },
     { _id: 6076da6c5706ebd01e1be6d0,
     listing_id: 432233,
     date: '2021-02-11',
     available: 'f',
     price: '$300.00',
     adjusted_price: '$300.00',
     minimum_nights: 2,
     maximum_nights: 100 },
     { _id: 6076da6c5706ebd01e1be6d3,
     listing_id: 432233,
     date: '2021-02-15',
     available: 't',
     price: '$300.00',
     adjusted_price: '$300.00',
     minimum_nights: 2,
     maximum_nights: 100 },
     ... 161 more items ]
    

    Notice that the output displays the results matching the query maximum_nights: 100 and price: $300.00 indicating that our query has been successfully processed.

Conclusion

The Helm chart simplifies the deployment and configuration of MongoDB-based containers on Red Hat OpenShift Container Platform running on IBM Power Systems. After configuring the Helm chart as required, any application could connect to MongoDB running on OpenShift Container Platform. It is possible to customize Helm charts based on the type of application and user requirement, for example, you can upgrade or roll back deployments. Also, note that Helm plays a pivotal role in streamlining CI/CD pipelines.

For more details about how to create and use Helm charts, refer:
https://helm.sh/docs/intro/using_helm/