MongoDB

MongoDB the General Purpose, Document Based, Distributed Database

MongoDB

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

quick start

prerequisites

Before you can get started with the operator you need either an account on MongoDB Cloud Manager or install MongoDB Ops Manager outside of the Konvoy cluster on a dedicated VM.

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 you can find here.

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

install the operator

First clone the mongodb-enterprise-kubernetes repository, and change to the mongodb-enterprise-kubernetes folder.

git clone https://github.com/mongodb/mongodb-enterprise-kubernetes.git
cd mongodb-enterprise-kubernetes

Next create the mongodb namespace.

kubectl create namespace mongodb

We then install the MongoDB operator.

helm template helm_chart > operator.yaml
kubectl apply -f operator.yaml

When clusters get created using the operator they need to 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
metadata:
  name: "ops-manager-secret"
  namespace: mongodb
stringData:
  user: "JXPIDQEA"      # This is the Public Key value
  publicApiKey: "<Paste the privateApiKey value from Cloud Manager here!>"
EOF

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=<first.last@example.com>" --from-literal="publicApiKey=<my-public-api-key>"

Next we create the configmap ops-manager-cm. The baseUrl is https://cloud.mongodb.com 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
metadata:
  name: ops-manager-cm
  namespace: mongodb
data:
  projectName: "myproject"
  baseUrl: https://cloud.mongodb.com
EOF

install the cluster

The MongoDB operator allows you to create different cluster types.

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

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

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

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

kubectl exec -ti -n mongodb mongodb-rs-0 bash

In the pod we run the mongo shell.

./var/lib/mongodb-mms-automation/mongodb-linux-x86_64-4.0.6/bin/mongo

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

First delete the cluster.

kubectl delete MongoDB mongodb-rs -n mongodb

Next delete the secret and config map.

kubectl delete secret ops-manager-secret -n mongodb
kubectl delete cm ops-manager-cm -n mongodb

Last we delete the operator

kubectl delete -f operator.yaml

information

documentation

release notes

license

maintenance & support