Deploying a MongoDB database instance with a custom resource

After you install the MongoDB service on Cloud Pak for Data, you must deploy a database instance. You can use the MongoDB OpenShift® command-line interface to deploy the database by creating a custom resource.

Before you begin

Best practice: You can run the commands in this task exactly as written if you set up environment variables. For instructions, see Setting up installation environment variables.

Ensure that you source the environment variables before you run the commands in this task.

Deploy the MongoDB Ops Manager before you deploy the MongoDB database instance. For more information, see Deploying MongoDB Ops Manager with a custom resource.

Procedure

  1. Set the following environment variables:
    1. Set the MGDB_INSTANCE_NAME environment variable to the name that you want to use for this database instance.
      export MGDB_INSTANCE_NAME=<name>
    2. Set the MGDB_VERSION environment variable to the version of the database to deploy.
      export MGDB_VERSION=<version>

      Use the following table to determine the appropriate value:

      Cloud Pak for Data version Service instance versions
      (Pick one)
      5.0.3 6.0.16-ent, 7.0.12-ent
      5.0.2 6.0.15-ent, 7.0.11-ent
      5.0.1 6.0.15-ent, 7.0.11-ent
      5.0.0 5.0.23-ent, 6.0.12-ent
    3. Set the OPS_MANAGER_INSTANCE_NAME environment variable to the MongoDB Ops Manager instance deployed in the project.
      export OPS_MANAGER_INSTANCE_NAME=<name>
    4. Set the STG_CLASS_BLOCK environment variable to the block storage class you want to use for this database instance.
      export STG_CLASS_BLOCK=<storage>
  2. Run the following command to deploy your database:
    cat <<EOF | oc apply -f -
    apiVersion: mongodb.cpd.ibm.com/v1
    kind: CPDMongoDB
    metadata:
      name: ${MGDB_INSTANCE_NAME}     
      namespace: ${PROJECT_CPD_INST_OPERANDS}
    spec:
      forceDeleteResource: false
      license:
        accept: true
      version: "${MGDB_VERSION}" 
      opsManager: ${OPS_MANAGER_INSTANCE_NAME}     
      replicas: 1
      storageSize: "2G"
      storageClass: ${STG_CLASS_BLOCK}     
      resources:
        requests:
          memory: 4Gi
          cpu: 1
        limits:
          memory: 4Gi
          cpu: 1
    EOF
    Tip: To automatically remove Persistent Volume Claims (PVCs) and secrets when you delete an instance, set the forceDeleteResources key under the spec key to true.

What to do next

MongoDB is ready to use. To get started with MongoDB, see Administering the MongoDB service and Working with MongoDB databases.