MongoDB the General Purpose, Document Based, Distributed Database


MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era.

Quick Start


Before you can get started with the operator you need either

Once you have either access to Cloud Manager or your own Ops Manager, you use it to create an api key and to whitelist the ips of your Konvoy cluster worker nodes.

For Cloud Manager, you’ll need to configure a Programmatic API key and an IP whitelist of your Konvoy cluster worker nodes. The steps for creating the API key are here.

For Ops Manager go to your account settings. There create an api key and whitelist the ips of your Konvoy cluster worker nodes.

Install the Operator

  1. Clone the mongodb-enterprise-kubernetes repository, and change to the mongodb-enterprise-kubernetes folder.

    git clone
    cd mongodb-enterprise-kubernetes
  2. Create the mongodb namespace.

    kubectl create namespace mongodb
  3. Install the MongoDB operator.

    helm template helm_chart > operator.yaml
    kubectl apply -f operator.yaml
  4. When clusters are created using the operator, they must be able to access either MongoDB Cloud Manager or MongoDB Ops Manager. A secret with the credentials and a config map with the respective manager address and project is required.

    For MongoDB Cloud Manager you create the ops-manager-secret the following way. In the yaml snippet, set the user key in the secret to the programmatic api key publicApiKey value and, albeit confusing, set the publicApiKey value of the secret to the privateApiKey value from Cloud Manager you copied when creating the key.

    cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: Secret
      name: "ops-manager-secret"
      namespace: mongodb
      user: "JXPIDQEA"      # This is the Public Key value
      publicApiKey: "<Paste the privateApiKey value from Cloud Manager here!>"

    For MongoDB Ops Manager you create the ops-manager-secret the following way.

    kubectl -n mongodb create secret generic ops-manager-secret --from-literal="user=<>" --from-literal="publicApiKey=<my-public-api-key>"
  5. Create the configmap ops-manager-cm. The baseUrl is if you use MongoDB Cloud Manager, or http://<ops-manager-hostname>:8080 if you use MongoDB Ops Manager.

    cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: ConfigMap
      name: ops-manager-cm
      namespace: mongodb
      projectName: "myproject"

Install the Cluster

The MongoDB operator allows you to create different cluster types.

In the following procedure, we create a MongoDB cluster of type replica set.

cat <<EOF | kubectl apply -f -
kind: MongoDB
  name: mongodb-rs
  namespace: mongodb
  members: 3
  version: 4.0.6
  project: ops-manager-cm
  credentials: ops-manager-secret
  type: ReplicaSet
  persistent: true

Checking on the pods in the mongodb namespace, you should see the following.

kubectl get pods -n mongodb

NAME                                          READY   STATUS    RESTARTS   AGE
mongodb-enterprise-operator-6c9999fd8-vc4g9   1/1     Running   0          22m
mongodb-rs-0                                  1/1     Running   0          2m9s
mongodb-rs-1                                  1/1     Running   0          119s
mongodb-rs-2                                  1/1     Running   0          113s

In the ops manager UI, switch to the organization named myproject (drop down under your user name top right); you should also see the cluster once you switch to that organization.

Access the Cluster

  1. Exec into one of the mongodb-rs-* pods.

    kubectl exec -ti -n mongodb mongodb-rs-0 bash
  2. In the pod, run the mongo shell.

  3. Use the mongo shell command rs.status() to see the status of the cluster.

    mongodb-rs:PRIMARY> rs.status()
      "members" : [
          "_id" : 0,
          "name" : "mongodb-rs-0.mongodb-rs-svc.mongodb.svc.cluster.local:27017",
          "_id" : 1,
          "name" : "mongodb-rs-1.mongodb-rs-svc.mongodb.svc.cluster.local:27017",
          "_id" : 2,
          "name" : "mongodb-rs-2.mongodb-rs-svc.mongodb.svc.cluster.local:27017",

Delete the Cluster and Operator

  1. Delete the cluster.

    kubectl delete MongoDB mongodb-rs -n mongodb
  2. Delete the secret and config map.

    kubectl delete secret ops-manager-secret -n mongodb
    kubectl delete cm ops-manager-cm -n mongodb
  3. Delete the operator

    kubectl delete -f operator.yaml



Release Notes


maintenance & support