Important
This section is for single Kubernetes cluster deployments only. For multi-Kubernetes cluster MongoDB deployments, see Overview.
The MongoDB Controllers for Kubernetes Operator uses the Kubernetes API and tools to manage MongoDB clusters running within your Kubernetes cluster. Kubernetes Operator works together with MongoDB Cloud Manager or Ops Manager. This tutorial demonstrates how to deploy and connect to your first MongoDB 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.
Kubernetes nodes running on supported hardware architectures.
The MongoDB Shell installed on your local machine.
Procedure
Add the MongoDB Helm Charts for Kubernetes repository to Helm.
helm repo add mongodb https://mongodb.github.io/helm-chartsInstall the MongoDB Controllers for Kubernetes Operator
To install the Kubernetes Operator with Helm, see the instructions in the repository.
Example
The following command installs the MongoDB Controllers for Kubernetes Operator in the mongodb namespace with the optional --create-namespace option. By default, Kubernetes Operator uses the default namespace.
helm install kubernetes-operator mongodb/mongodb-kubernetes --namespace mongodb --create-namespaceConfigure the Kubernetes Operator
Click Create New API Keys or Use Existing API Keys.
Complete the form. To learn more, see Programmatic Access to Cloud Manager.
Click Generate Key and YAML.
Copy and save the ConfigMap.
Copy and save the generated config-map.yaml file.
Example:
apiVersion: v1kind: ConfigMapmetadata: name: my-project namespace: mongodbdata: baseUrl: https://cloud.mongodb.com
projectName: my-project # this is an optional parameter orgId: 5ecd252f8c1a75033c74106c # this is a required parameterTo learn more, see the parameter descriptions.
Deploy the MongoDB replica set resource.
Copy and save the following YAML file:
apiVersion: mongodb.com/v1kind: MongoDBmetadata: name: demo-mongodb-cluster-1 namespace: mongodbspec: members: 3 version: 8.0.0 type: ReplicaSet security: authentication: enabled: true modes: ["SCRAM"] cloudManager: configMapRef: name: my-project 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: 10GiRun the following command:
kubectl apply -f <replica-set-conf>.yaml
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: v1kind: Secretmetadata: name: mms-user-1-password # corresponds to user.spec.passwordSecretKeyRef.nametype: OpaquestringData: password: <my-plain-text-password> # corresponds to user.spec.passwordSecretKeyRef.keyFor a Base64-encoded password, create and save the following YAML file:
apiVersion: v1kind: Secretmetadata: name: mms-user-1-password # corresponds to user.spec.passwordSecretKeyRef.nametype: Opaquedata: password: <base-64-encoded-password> # corresponds to user.spec.passwordSecretKeyRef.keyCreate a database user.
Copy and save the following MongoDB User Resource Specification file:
apiVersion: mongodb.com/v1kind: MongoDBUsermetadata: name: mms-scram-user-1spec: 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 authentication roles: - db: "admin" name: "clusterAdmin" - db: "admin" name: "userAdminAnyDatabase" - db: "admin" name: "readWrite"Run the following command:
kubectl apply -f <database-user-conf>.yaml
Connect to the MongoDB replica set.
Perform the following steps in the Cloud Manager application:
Click Deployment in the left navigation.
Click for the deployment to which you want to connect.
Click Connect to this instance.
Run the connection command in a terminal to connect to the deployment.