OpenShift Quick Start
On this page
- Prerequisites
- Procedure
- Clone the MongoDB Enterprise Kubernetes Operator repository.
- Create a namespace for your Kubernetes deployment.
- Configure
kubectl
to default to your namespace. - Create a secret that contains credentials authorized to pull images from the
registry.connect.redhat.com
repository. - Install the MongoDB Enterprise Kubernetes Operator
- Create credentials and store them as a secret.
- Invoke the following command to create a ConfigMap.
- Deploy the 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 replica set.
Important
This section is for single Kubernetes cluster deployments only. For multi-Kubernetes-cluster deployments, see Multi-Kubernetes-Cluster Quick Start.
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 Cloud Manager or Ops Manager from OpenShift with Kubernetes Operator.
Prerequisites
This tutorial requires:
A running Cloud Manager or Ops Manager cluster.
Procedure
Clone the MongoDB Enterprise Kubernetes Operator repository.
git clone https://github.com/mongodb/mongodb-enterprise-kubernetes.git
Create a secret that contains credentials authorized to pull images from the registry.connect.redhat.com
repository.
If you use the Kubernetes Operator to deploy MongoDB resources to multiple namespaces or with a cluster-wide scope, create the secret only in the namespace where you intend to deploy the Kubernetes Operator. The Kubernetes Operator synchronizes the secret across all watched namespaces.
If you have not already, obtain a Red Hat subscription.
Create a Registry Service Account.
Click on your Registry Service Account, then click the Docker Configuration tab.
Download the
<account-name>-auth.json
file and open it in a text editor.Copy the
registry.redhat.io
object, and paste another instance of this object into the file. Remember to add a comma after the first object. Rename the second objectregistry.connect.redhat.com
, then save the file:{ "auths": { "registry.redhat.io": { "auth": "<encoded-string>" }, "registry.connect.redhat.com": { "auth": "<encoded-string>" } } } Create an
openshift-pull-secret.yaml
file and add the contents of the modified<account-name>-auth.json
file asstringData
named.dockerconfigjson
to theopenshift-pull-secret.yaml
secret file.apiVersion: v1 kind: Secret metadata: name: openshift-pull-secret stringData: .dockerconfigjson: | { "auths": { "registry.redhat.io": { "auth": "<encoded-string>" }, "registry.connect.redhat.com": { "auth": "<encoded-string>" } } } type: kubernetes.io/dockerconfigjson The value you provide in the
metadata.name
field contains the secret name. Provide this value when asked for the<openshift-pull-secret>
.Create a secret from the
openshift-pull-secret.yaml
file in the same namespace in which you will deploy the Kubernetes Operator.oc apply -f openshift-pull-secret.yaml -n <metadata.namespace>
Install the MongoDB Enterprise Kubernetes Operator
Invoke the following oc command to install the CustomResourceDefinitions for MongoDB deployments:
oc apply -f crds.yaml Add your
<openshift-pull-secret>
to theServiceAccount
definitions in the MongoDB Enterprise Kubernetes Operator YAML file.# Source: mongodb-enterprise-operator/templates/serviceaccount.yaml apiVersion: v1 kind: ServiceAccount metadata: name: enterprise-operator namespace: mongodb imagePullSecrets: - name: <openshift-pull-secret> apiVersion: v1 kind: ServiceAccount metadata: name: mongodb-enterprise-appdb namespace: mongodb imagePullSecrets: - name: <openshift-pull-secret> apiVersion: v1 kind: ServiceAccount metadata: name: mongodb-enterprise-database-pods namespace: mongodb imagePullSecrets: - name: <openshift-pull-secret> Invoke the following oc command to install Kubernetes Operator:
oc apply -f mongodb-enterprise-openshift.yaml
Create credentials and store them as a secret.
Run the following command:
Note
Provide your Public and Private Key values for the following parameters. To learn more, see Create Credentials for the Kubernetes Operator.
kubectl -n mongodb \ create secret generic ops-manager-admin-key \ --from-literal="publicKey=<publicKey>" \ --from-literal="privateKey=<privateKey>"
Invoke the following command to create a ConfigMap.
cat <<EOF | kubectl apply -f - apiVersion: v1 kind: ConfigMap metadata: name: my-project namespace: mongodb data: projectName: myProjectName # this is an optional parameter; when omitted, the Operator creates a project with the resource name orgId: 5b890e0feacf0b76ff3e7183 # this is a required parameter baseUrl: https://ops.example.com:8443 EOF
Key | Type | Description | Example |
---|---|---|---|
metadata.name | string | my-project | |
metadata.namespace | string | mongodb | |
data.projectName | string | Label for your Ops Manager Project. The Kubernetes Operator creates the Ops Manager project if it does
not exist. If you omit the To use an existing project in a Cloud Manager or Ops Manager
organization, locate
the | myProjectName |
data.orgId | string | Required. 24 character hex string that uniquely identifies your Cloud Manager or Ops Manager Organization. Important
Specify an existing Organization: NoteYou must have the Organization Project Creator role to create a new project within an existing Cloud Manager or Ops Manager organization. If you provide an empty string as your | 5b890e0feacf0b76ff3e7183 |
data.baseUrl | string | URL to your Ops Manager Application including the FQDN and port number. ImportantIf you deploy Ops Manager with the Kubernetes Operator and Ops Manager will
manage MongoDB database resources deployed outside of the Kubernetes
cluster it's deployed to, you must set NoteIf you're using Cloud Manager, set the | https://ops.example.com:8443 |
Deploy the 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 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.