Installing MongoDB for Product Master

To use the Digital Asset Management (DAM) or Machine learning (ML) features of the Product Master service, you need to install MongoDB by using the Helm chart.

Before you begin

You need to have the following installed:
  • Helm
  • vCPU - 3
  • Memory - 2 Gi RAM

Procedure

  1. Log in to your Red Hat® OpenShift® cluster as an instance administrator.
    oc login OpenShift_URL:port
  2. Change to the project (namespace) where Product Master is installed by using the following command.
    oc project <namespace>
  3. Assign required privileges for this service by using the following command.
    oc adm policy add-scc-to-user privileged system:serviceaccount:<namespace>:mongodb-Kubernetes-operator
    oc adm policy add-scc-to-user privileged system:serviceaccount:<namespace>:mongodb-database
  4. List all the releases for the namespace by using the following command.
    helm repo list
    Output
    NAME URL
    mongodb https://mongodb.github.io/helm-charts
  5. Add the MongoDB helm-charts repository to Helm by using the following command.
    helm repo add MongoDB https://mongodb.github.io/helm-charts
  6. Install MongoDB by using the following command.
    helm install community-operator MongoDB/community-operator 
  7. Create PersistentVolume YAML files by using the following command.
    cat <<EOF| oc apply –f -
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      labels:
        app: productmaster-mongodb-svc
      name: logs-volume-productmaster-mongodb-0
      namespace: <namespace>
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: <storage_class>
      resources:
        requests:
          storage: 2G
      volumeMode: Filesystem
    EOF
    cat <<EOF| oc apply –f -
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      labels:
        app: productmaster-mongodb-svc
      name: data-volume-productmaster-mongodb-0
      namespace: <namespace>
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: <storage_class>
      resources:
        requests:
          storage: 2G
      volumeMode: Filesystem
    EOF
  8. Create and apply the CR file with the following entries. Update the username and password fields in the CR file.
    cat <<EOF| oc apply –f -
    apiVersion: mongodbcommunity.mongodb.com/v1
    kind: MongoDBCommunity
    metadata:
      name: productmaster-mongodb
    spec:
    #To create multiple replicas, update the value of the members property to the number of replicas required
      members: 1
      type: ReplicaSet
      version: "7.0.2"
      security:
        authentication:
          modes: ["SCRAM-SHA-1"]
      users:
        - name: <mongodb_username>
          db: admin
          passwordSecretRef:
            name: my-user-password
          roles:
            - name: clusterAdmin
              db: admin 
            - name: userAdminAnyDatabase
              db: admin 
            - name: readWriteAnyDatabase
              db: admin
            - name: backup
              db: admin
          
          scramCredentialsSecretName: my-scram
      statefulSet:
        spec:
          serviceName: productmaster-mongodb-svc
          selector: {}
    
    # the user credentials will be generated from this secret
    # once the credentials are generated, this secret is no longer required
    ---
    apiVersion: v1
    kind: Secret
    metadata:
      name: my-user-password
    type: Opaque
    stringData:
      password: <mongodb_password>
    EOF
  9. View MongoDB instance and MongoDB operator statuses by using the following command.
    oc get pods | grep mongodb

    Example output

    NAME                                 READY   STATUS   RESTARTS     AGE
    mongodb-kubernetes-operator-857946dd48-wb29f    1/1     Running     0        1m40s
    productmaster-mongodb-0                         2/2     Running     0        13s
  10. Go to the MongoDB instance by using the following command.
    oc rsh productmaster-mongodb-0
  11. Use the following commands to ensure that the MongoDB instance is up and running with username and password.
    mongosh
    use admin
    db.auth (“username”,”password”)
    use {{ db_name }
    db.createcollection(‘test1’)
  12. Ensure that you have the same service name as specified in the mongodb_cr_openshift file. See the service details by using the following command.
    oc get svc | grep mongodb

What to do next

Specify the following in the app_secrets.yaml file during the IBM® Product Master installation.
Property Value
mongodb_host <mongodb_services_name>
mongodb_name <mongodb_db_name>
mongodb_pass <mongodb_password>
mongodb_user <mongodb_username>