a couple of weeks ago I was trying to deploy MongoDB in AKS using the MongoDB Enterprise Operator and had trouble finding a simple tutorial to make the thing work. This post intends to fill that gap with a straight to the point approach.
Prerequisites
Be sure to deploy AKS with a set of nodes with at least 8GB of RAM. I used Standard_D3_v2
First clone the MongoDB Enterprise Kubernetes repo
1git clone https://github.com/mongodb/mongodb-enterprise-kubernetes.git
2cd mongodb-enterprise-kubernetes
Create the MongoDB namespace inside your cluster
1kubectl create namespace mongodb
Deploy the Custom Resource Definitions
1kubectl apply -f crds.yaml
Deploy the MongoDB Enterprise Operator
1kubectl apply -f mongodb-enterprise.yaml
Create a secret for the Ops Manager
As part of the installation you’ll have to deploy the Ops Manager to the cluster. Be sure to set a complex password otherwise the Ops Manager wont start.
1kubectl create secret generic ops-manager-admin-secret `
2 --from-literal=Username="<Username>" `
3 --from-literal=Password="<Password>" `
4 --from-literal=FirstName="<Name>" `
5 --from-literal=LastName="<Last Name>" `
6 -n mongodb
Deploy the Ops Manager
Create ops-manager.yaml with the following contents (Note that we are using 1 replica):
1---
2apiVersion: mongodb.com/v1
3kind: MongoDBOpsManager
4metadata:
5 name: ops-manager
6spec:
7 # the number of Ops Manager instances to run. Set to value bigger
8 # than 1 to get high availability and upgrades without downtime
9 replicas: 1
10
11 # the version of Ops Manager distro to use
12 version: 4.2.4
13
14 # the name of the secret containing admin user credentials.
15 # Either remove the secret or change the password using Ops Manager UI after the Ops Manager
16 # resource is created!
17 adminCredentials: ops-manager-admin-secret
18
19 # the Ops Manager configuration. All the values must be of type string
20 configuration:
21 mms.fromEmailAddr: "admin@thecompany.com"
22
23 # the application database backing Ops Manager. Replica Set is the only supported type
24 # Application database has the SCRAM-SHA authentication mode always enabled
25 applicationDatabase:
26 members: 3
27 version: 4.2.0
28 persistent: true
29 podSpec:
30 cpu: "0.25"
Deploy the Ops Manager:
1kubectl apply -f .\ops-manager.yaml -n mongodb
Wait until the Ops Manager is ready
1kubectl get om -n mongodb -o yaml -w
Port Forward so you can access Ops Manager from your PC
1kubectl port-forward pods/ops-manager-0 8080:8080 -n mongodb
Setup de Ops Manager
Login into the Ops Manager (http://localhost:8080) using the same user and password you deployed as a secret.
Create an Organization. Copy the Organnization Id so you can use it later.
Create Public & Private Key for the Organization. Copy both keys so you can use them later.
White List the Operator IPs. To get the IPs run:
1kubectl get po --selector=app=mongodb-enterprise-operator -n mongodb -o jsonpath='{.items[*].status.podIP}'
Create a secret that will be used by the operator to connect with the ops manager
Use the Public and Private keys copied in previous steps to run tyhe following command:
1kubectl -n mongodb `
2 create secret generic my-credentials `
3 --from-literal="user=<private key>" `
4 --from-literal="publicApiKey=<public key>"
Create a project
Create project.yaml with the following contents and be sure to replace the Organization Id you copied in previous steps:
1---
2apiVersion: v1
3kind: ConfigMap
4metadata:
5 name: mongodb-test
6data:
7 projectName: mongodb-test
8 baseUrl: http://ops-manager-svc.mongodb.svc.cluster.local:8080
9
10 orgId: <Organization Id>
Deploy the project ConfigMap definition:
1kubectl apply .\project.yaml -n mongodb
Create a standalone MongoDB instance
Create standalone.yaml with the following contents:
1apiVersion: mongodb.com/v1
2kind: MongoDB
3metadata:
4 name: my-standalone
5spec:
6 version: 4.2.1
7 type: Standalone
8 opsManager:
9 configMapRef:
10 name: mongodb-test
11 credentials: my-credentials
12
13 # This flag allows the creation of pods without persistent volumes. This is for
14 # testing only, and must not be used in production. 'false' will disable
15 # Persistent Volume Claims. The default is 'true'
16 persistent: false
Deploy the standalone MongoDB:
1kubectl apply -f .\standalone.yaml -n mongodb
Enjoy! You have MongoDB up and running!
To learn more about the MongoDB Enterprise Operator please check here.
Comments