Overview

Skill Level: Beginner

This recipe describes how to deploy MongoDB, a cross-platform document-oriented database, into IBM Cloud Private, IBM's new Kubernetes based private cloud, by using helm charts and persistent volumes.

Ingredients

  • IBM Cloud Private 2.1.0.1
  • Kubectl command line (optional...get it here)
  • Persistent volume
  • IBM MongoDB 3.6.0 Commuity Edition-Helm chart

A couple things to note: This recipe deploys the developer edition and should be used for development purposes only.

Step-by-step

  1. Install IBM Cloud Private 2.1.0.1

    First, you will need to install IBM Cloud Private 2.1.0.1. Detailed instructions are here. Once you have it installed, then the steps will be:

    • Create a persistent volume or use Dynamic Storage
    • Install MongoDB with advanced options
    • Validate MongoDB connection
    • Connect and manage MongoDB instance with IBM Data Server Manager
  2. Create Persistent Volume or use Dynamic Storage

    To deploy MongoDB, you need to create a persistent volume that uses the ReadWriteOnce(RWO) access mode. This can be done in the UI, and should ideally be created before the deployment. Log into IBM Cloud Private, and use the upper left menu to navigate to the Storage page

    003-1

    On the storage page, click “Create PersistenceVolume”

    004-1

    007-1

    006-1

    In this example, I created an 6GB Host path volume, that uses the ReadWriteOnce access mode, and it will be retained if the pod is removed. In your case, you would probably want to use NFS or other shared storage so that if a node drops the MongoDB pod will come back up onto a different node and reconnect to the same volume. However, if you do not want to manage an NFS server, you can use HostPath as an easy solution for initial testing.

    You will soon see that the default volume size for the MongoDB deployment specified in the helm chart is 8GB, so if you need more, go ahead and create a larger volume first, then match the size in the Advanced Installation fields that you will see shortly.

    To use dynamic storage like GlusterFS, you can check the “persistence.useDynamicProvisioning”. IBM Cloud Private will automatically create a dynamic persistence volume for you.

  3. Get to the MongoDB Helm Chart

    Next install MongoDB itself. With IBM Cloud Private, you have 2 ways to install MongoDB.

    • IBM Cloud Private App Center UI
    • From the command line using “Helm” commands

    For this example, we will use the App Center. However, if you want to use the command line, you can directly access the helm charts here: https://github.com/IBM/charts. Either path is fine, and as we both know, if you love kubectl and helm commands, then using the helm charts directly is a great option.

    For the UI path, open IBM Cloud Private 2.1.0.1. Once you log in, you’ll see the dashboard view:

    catalog-1

    Select the upper left menu and see the dropdown options, select “Catalog” then “Helm Charts”.

    catalog-mongo

    Scroll or search until you see “ibm-mongodb-dev”, and click to install.

    prov-mongo

    As a general rule, most all services have important fields you need to fill in before you can properly install, which is why you’ll see the advanced installation options. MongoDB is no different, but since we need you to accept the license agreement, the license agreement will appear first (4 pages for your reading pleasure), and then the advanced options will appear.

  4. Specify Advanced Settings

    After you click “Configuration”, you’ll see quite a few advanced settings, but I’ll just highlight the ones you really need to worry about.

    Step 1 of 4:

    p1

    You need to set the release name, target namespace and accept the license at this section.

    Three major architectures are now available for MongoDB Community Edition on IBM Cloud Private worker nodes:

    • AMD64 / x86_64
    • s390x
    • ppc64le

    Architecture scheduling preferences are required to specify supported architectures to be used during scheduling and includes ability to give preference to certain architecture(s) over another.

    Specify architecture (amd64, ppc64le, s390x) and weight to be used for scheduling as follows : 0 – Do not use 1 – Least preferred 2 – No preference 3 – Most preferred

     

    Step 2 of 4:

    p2

    Here it specifies the docker image to deploy MongoDB: mongodb. You can leave these fields as default.

    Docker Repository:  Image repository

    Docker image tag:  Image tag

    Docker image pull policy:  Image pull policy

    On this page you can also config the data volume to persist MongoDB runtime data.

     

    Step 3 of 4:

    p3

    You can configure MongoDB resources and services here by setting the CPU, Memory limits and editing node port.

     

    Step 4 of 4:

    p4

    MongoDB user name:

    This is the admin username of MongoDB.

    Password for MongoDB admin user:

    Set the password for the admin user in this field. If you keep it blank, a random password will be generated for the admin user. To get the password generated, use the following command:

    kubectl get secret –namespace <namespace name> <secret name>-o jsonpath=”{.data.password}” | base64 –decode; echo

  5. Deploy the MongoDB Helm Chart

    Once you are ready (you have accepted the license, created your persistent volume, and filled in all the advanced installation details) click “Review and Install”, then “Install”, and you are installing!

    Depending on compute and storage speeds, it may take several minutes to install and set up the sample database (which is creates by default). To monitor the progress, you have two options:

    From the UI, click on “Workloads”, select the mongodb application (it’s actually a ‘deployment’ in Kubernetes terms), locate the pod and select it, then select the Logs tab.

    From the command line: find the pod name and monitor its log:

    kubectl get pods

    kubectl logs -f <pod name>

  6. Start Using MongoDB

    Once MongoDB is installed, you are ready to use it. To get the IP and Port of it, get into Workloads/Application tag:

    8

    The MongoDB service is named with:

    <namespace>-<name>-ibm-mongodb-dev

     

    Install a Mongodb Client and use the following command to connect to mongodb:

    mongo <ip>:<port>/<database> -u <username> -p <password>

     mongo

  7. Connect and manage MongoDB instance with IBM Data Server Manager

    IBM Data Server Manager(DSM) supports Admin, Monitor and Run SQLs on Open Source DB like MongoDB and PostgreSQL.

    For details, please check:

    https://developer.ibm.com/recipes/tutorials/deploy-dsm-into-ibm-cloud-private/

    add2-2

     

     In DSM, these 3 helm releases are added automatically as db connections. Admin, Monitor, Run SQLs are supported for them.

    dsm0

     Monitoring your Open Source DB performance with IBM DSM.

    dsm1

    Manage the collections, documents and indexes of your database with IBM DSM. Feel free to give a try.

  8. Conclusion

    Using this recipe, you can get MongoDB community edition running in IBM Cloud Private 2.1.0.1. While it’s not quite as simple as it should be, these steps will get you a great database to use as you try out IBM Cloud Private 2.1.0.1.

    Good luck and happy Databasing!

3 comments on"Deploy MongoDB into IBM Cloud Private"

  1. Hello i try as you says but when i deploy the chart i obtain an error FailedBinding –> no persistent volumes available for this claim and no storage class is set” in storage volume claim. This happen both if a declare or not a storage class name. My persistent volume is:
    {
    “apiVersion”: “v1”,
    “kind”: “PersistentVolume”,
    “metadata”: {
    “name”: “mongodb”,
    “resourceVersion”: “62921”
    },
    “spec”: {
    “capacity”: {
    “storage”: “20Gi”
    },
    “hostPath”: {
    “path”: “/opt/data/mongodb”,
    “type”: “”
    },
    “accessModes”: [
    “ReadWriteOnce”
    ],
    “persistentVolumeReclaimPolicy”: “Retain”,
    “storageClassName”: “mongodb”
    }
    }

    I am working with ICP 2.1.0.2 and i am trying to deploy an ibm-mongodb-dev V 1.1.2.

    Any suggestion ?

  2. anup@BigData August 10, 2018

    edit the deployment and ensure “spec”: {
    “volumes”: [
    {
    “name”: “mongo-ibm-mongodb-dev-datavolume”,
    “persistentVolumeClaim”: {
    “claimName”: “pv001”

    submit the changes and you should see in the events that it pulls up the container.

  3. danielap.201907300905 October 24, 2019

    Any recommendations regarding how to handle memory allocation? I have a pod that keeps crashing when trying to get large collections. With no swap support from k8s, the only solution I can think of is adding more memory, but this feels a bit silly as the collection will probably keep growing.

Join The Discussion