Navigation

Quick Start

On this page

MongoDB Enterprise Kubernetes Operator uses the Kubernetes API and tools to manage MongoDB clusters. Kubernetes Operator works together with MongoDB Cloud Manager or Ops Manager. This tutorial demonstrates how to deploy and connect to your first replica set in MongoDB Cloud Manager with Kubernetes Operator. You can use Kind to quickly set up a cluster. To learn more, see Kind.

Prerequisites

This tutorial requires:

  • A running MongoDB Cloud Manager cluster.
  • A running Kubernetes cluster.

Procedure

1

Add the MongoDB Helm Charts for Kubernetes repository to Helm.

helm repo add mongodb https://mongodb.github.io/helm-charts
2

Install the MongoDB Enterprise Kubernetes Operator

To install the Kubernetes Operator with the Helm Chart, see the instructions in the repository.

Example

The following command installs the MongoDB Enterprise Kubernetes Operator in the mongodb namespace with the optional --create-namespace option. By default, Kubernetes Operator uses the default namespace.

helm install enterprise-operator mongodb/enterprise-operator --namespace mongodb --create-namespace
3

Configure kubectl to default to your namespace.

If you haven’t already, run the following command to execute all kubectl commands in the namespace you created:

kubectl config set-context $(kubectl config current-context) --namespace=mongodb
4

Configure the Kubernetes Operator

  1. Go to the Kubernetes Setup Page in the Cloud Manager UI.
  2. Click Create New API Keys or Use Existing API Keys.
  3. Complete the form. To learn more, see Programmatic Access to Cloud Manager.
  4. Click Generate Key and YAML.
5

Copy and save the ConfigMap.

Copy and save the generated config-map.yaml file.

Example:

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-project
  namespace: mongodb
data:
  baseUrl: https://cloud.mongodb.com

  # Optional Parameters
  # projectName: My Ops/Cloud Manager Project

  ordId: 5ecd252f8c1a75033c74106c

To learn more, see the parameter descriptions.

6

Copy and save the Secret.

Copy and save the generated secret.yaml file.

Example:

apiVersion: v1
kind: Secret
metadata:
  name: organization-secret
  namespace: mongodb
stringData:
  user: <public_key>
  publicAPIKey: <private_key>

For security purposes, MongoDB Cloud Manager displays this file only once.

7

Apply the ConfigMap and Secret.

Run the following command:

kubectl apply -f secret.yaml -f config-map.yaml
8

Deploy the replica set resource.

  1. Copy and save the following YAML file:

    apiVersion: mongodb.com/v1
    kind: MongoDB
    metadata:
      name: demo-mongodb-cluster-1
      namespace: mongodb
    spec:
      members: 3
      version: 4.4.5-ent
      type: ReplicaSet
      authentication:
        enabled: true
        modes: ["SHA"]
      cloudManager:
        configMapRef:
          name: myproject
      credentials: organization-secret
      persistent: true
      podSpec:
        podTemplate:
          spec:
           containers:
            - name: mongodb-enterprise-database
              resources:
                limits:
                  cpu: 2
                  memory: 1.5G
                requests:
                  cpu: 1
                  memory: 1G
                persistence:
                  single:
                    storage: 10Gi
    
  2. Run the following command:

    kubectl apply -f <replica-set-conf>.yaml
    
9

Create a secret with your database user password

You can choose to use a cleartext password or a Base64-encoded password. Plaintext passwords use stringData.password and Base64-encoded passwords use data.password.

Note

Provide your values for the following parameters. To learn more, see the parameter descriptions.

For a cleartext password, create and save the following YAML file:

apiVersion: v1
kind: Secret
metadata:
  name: mms-user-1-password
  # corresponds to user.spec.passwordSecretKeyRef.name
type: Opaque
stringData:
  password: <my-plain-text-password>
  # corresponds to user.spec.passwordSecretKeyRef.key

For a Base64-encoded password, create and save the following YAML file:

apiVersion: v1
kind: Secret
metadata:
  name: mms-user-1-password
  # corresponds to user.spec.passwordSecretKeyRef.name
type: Opaque
data:
  password: <base-64-encoded-password>
  # corresponds to user.spec.passwordSecretKeyRef.key
10

Create a database user.

  1. Copy and save the following YAML file:

    apiVersion: mongodb.com/v1
    kind: MongoDBUser
    metadata:
      name: mms-scram-user-1
    spec:
      passwordSecretKeyRef:
        name: mms-user-1-password
        # Match to metadata.name of the User Secret
        key: password
      username: "mms-scram-user-1"
      db: "admin" #
      mongodbResourceRef:
        name: "demo-mongodb-cluster-1"
        # Match to MongoDB resource using authenticaiton
      roles:
      - db: "admin"
        name: "clusterAdmin"
      - db: "admin"
        name: "userAdminAnyDatabase"
      - db: "admin"
        name: "readWrite"
      - db: "admin"
        name: "userAdminAnyDatabase"
    
  2. Run the following command:

    kubectl apply -f <database-user-conf>.yaml
    
11

Optional: View the newly created user in Cloud Manager or Ops Manager.

You can view the newly-created user in Cloud Manager or Ops Manager:

  1. From the Project’s Deployment view, click the Security tab.
  2. Click the MongoDB Users nested tab.
12

Connect to the replica set.

Perform the following steps in the Cloud Manager application:

  1. Click Deployment in the left navigation.
  2. Click ellipsis icon for the deployment to which you want to connect.
  3. Click Connect to this instance.
  4. Run the connection command in a terminal to connect to the deployment.