Deploying MongoDB with a custom resource

After you install the MongoDB service on Cloud Pak for Data, you must deploy a database. You can use the MongoDB OpenShift command-line interface to deploy the database by creating the CPDMongoDB 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.

Procedure

  1. Set the following environment variables:
    1. Set the DB_INSTANCE_NAME environment variable to the name that you want to use for this database instance:
      export DB_INSTANCE_NAME=<name>
    2. Set the DB_VERSION environment variable to the version of the database to deploy. Valid values are: 5.0.13, 6.0.2.
      export DB_VERSION=<version>
    3. Set the DB_OPS_MANAGER environment variable to the name that you want to use for the MongoDB OpsManager:
      export DB_OPS_MANAGER=<name>
    4. Set the STORAGE_CLASS_BLOCK environment variable to the block storage class you want to use for this database instance.
      export STORAGE_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: ${DB_INSTANCE_NAME}     
      namespace: ${PROJECT_CPD_INSTANCE}
    spec:
      forceDeleteResource: false
      license:
        accept: true
      version: "${DB_VERSION}" 
      opsManager: ${DB_OPS_MANAGER}     
      replicas: 1
      storageSize: "2G"
      storageClass: ${STG_CLASS_BLOCK}     
      resources:
        requests:
          memory: 4Gi
          cpu: 1
        limits:
          memory: 4Gi
          cpu: 1
    EOF
    Tip: To automatically remove pvcs and secrets when you delete an instance, set the spec.forceDeleteResources under the spec: key to true.