Quick Start for the Kubernetes Operator
On this page
- Prerequisites
- Procedure
- Add the MongoDB Helm Charts for Kubernetes repository to Helm.
- Install the MongoDB Enterprise Kubernetes Operator
- Configure
kubectl
to default to your namespace. - Configure the Kubernetes Operator
- Copy and save the ConfigMap.
- Copy and save the Secret.
- Apply the ConfigMap and Secret.
- Deploy the MongoDB replica set resource.
- Create a secret with your database user password
- Create a database user.
- Optional: View the newly created user in Cloud Manager or Ops Manager.
- Connect to the MongoDB replica set.
Important
This section is for single Kubernetes cluster deployments only. For multi-Kubernetes cluster MongoDB deployments, see Multi-Kubernetes-Cluster Quick Start.
The MongoDB Enterprise 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-charts
Install the MongoDB Enterprise Kubernetes Operator
To install the Kubernetes Operator with Helm, 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
Configure 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: v1 kind: ConfigMap metadata: name: my-project namespace: mongodb data: baseUrl: https://mongodb.prakticum-team.ru/proxy/cloud.mongodb.com projectName: my-project # this is an optional parameter orgId: 5ecd252f8c1a75033c74106c # this is a required parameter
To learn more, see the parameter descriptions.
Deploy the MongoDB replica set resource.
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 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: 10Gi Run 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: 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
Create a database user.
Copy and save the following MongoDB User Resource Specification 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" 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.