Install the MongoDB Enterprise Kubernetes Operator
On this page
Prerequisites and Considerations
Before you install the Kubernetes Operator, make sure you plan for your installation:
Choose a deployment topology.
Read the Considerations.
Complete the Prerequisites.
Note
This tutorial presumes some knowledge of Kubernetes and links to relevant Kubernetes documentation. If you are unfamiliar with Kubernetes, please review that documentation first.
Install with Kubernetes
The installation procedure varies based on how you want to configure your environment:
Note
Use the same namespace throughout
By default, the Kubernetes Operator deploys all resources in your Kubernetes cluster
to the namespace mongodb
. You can deploy Kubernetes Operator resources
to a different namespace by editing all values for
metadata.namespace
in mongodb-enterprise.yaml
:
##--- # Source: mongodb-enterprise-operator/templates/serviceaccount.yaml apiVersion: v1 kind: ServiceAccount metadata: name: mongodb-enterprise-operator namespace: production ##--- # Source: mongodb-enterprise-operator/templates/operator.yaml apiVersion: apps/v1 kind: Deployment metadata: name: mongodb-enterprise-operator namespace: production # Example truncated ...
Optional: Customize the Kubernetes Operator YAML before installing it.
To learn about optional Kubernetes Operator installation settings, see Operator kubectl and oc Installation Settings.
Note
To enable the Public Preview of static containers, which improve and simplify security, see Static Containers (Public Preview). We don't recommend using this feature in production while it's in Public Preview.
Populate the <version>
placeholder and run the following kubectl
command to deploy your chosen version of the Kubernetes Operator to your Kubernetes cluster:
kubectl apply -f https://raw.githubusercontent.com/mongodb/mongodb-enterprise-kubernetes/<version>/mongodb-enterprise.yaml
Use the MongoDB Helm Charts for Kubernetes.
Add the MongoDB Helm Charts for Kubernetes.
You can add the Kubernetes Operator Helm Chart locally by running:
helm repo add mongodb https://mongodb.github.io/helm-charts
Customize your Helm Chart before deploying it.
To learn about optional Kubernetes Operator installation settings, see Operator Helm Installation Settings.
Deploy the Kubernetes Operator.
Run the following helm
command to deploy the Kubernetes Operator to the
default namespace in your Kubernetes cluster:
helm install --upgrade enterprise-operator mongodb/enterprise-operator
You can pass the --namespace
and --create-namespace
flags to deploy
the Kubernetes Operator to a non-default namespace, like so:
helm install --upgrade enterprise-operator mongodb/enterprise-operator \ --namespace mongodb \ --create-namespace
Install a Specific Daily Build with Helm
MongoDB rebuilds Kubernetes Operator images every day to integrate the latest security and OS updates.
By default, helm
installs the latest build for the version of
the Kubernetes Operator you specify.
To install an earlier build, specify the build ID as a parameter with
--set build=<build-id>
. Build IDs are always in the format
-b<YYYYMMDD>T000000Z
, where <YYYYMMDD>
is the date that the
build you want to use was created.
Example
This example shows how to install the Kubernetes Operator with the latest image:
helm install enterprise-operator mongodb/enterprise-operator
This example shows how to install the Kubernetes Operator with the image created at midnight on February 5th, 2021:
helm install enterprise-operator mongodb/enterprise-operator \ --set build=-b20210205T000000Z
Note
MongoDB recommends using the default (latest) build.
Install with OpenShift
Before you begin, ensure that the MANAGED_SECURITY_CONTEXT
flag is set
to true
when you deploy the Kubernetes Operator to OpenShift. This value is
pre-defined in the values-openshift.yaml file.
The installation procedure varies based on how you want to configure your environment:
Note
Use the same namespace throughout
By default, the Kubernetes Operator deploys all resources in your Kubernetes cluster
to the namespace mongodb
. You can deploy Kubernetes Operator resources
to a different namespace by editing all values for
metadata.namespace
in mongodb-enterprise-openshift.yaml
:
##--- # Source: mongodb-enterprise-operator/templates/serviceaccount.yaml apiVersion: v1 kind: ServiceAccount metadata: name: enterprise-operator namespace: production ##--- # Source: mongodb-enterprise-operator/templates/operator.yaml apiVersion: apps/v1 kind: Deployment metadata: name: enterprise-operator namespace: production # Example truncated ...
Clone the MongoDB Enterprise Kubernetes Operator repository.
Invoke the following git
command:
git clone https://github.com/mongodb/mongodb-enterprise-kubernetes.git
Navigate to the directory in which you cloned the MongoDB Enterprise Kubernetes Operator repository.
For example, if you cloned the repository in your home directory, run:
cd ~/mongodb-enterprise-kubernetes
Install the CustomResourceDefinitions for MongoDB deployments.
Invoke the following oc command:
oc apply -f crds.yaml
Optional: Customize the Kubernetes Operator YAML before installing it.
To learn about optional Kubernetes Operator installation settings, see Operator kubectl and oc Installation Settings.
Note
To enable the Public Preview of static containers, which improve and simplify security, see Static Containers (Public Preview). We don't recommend using this feature in production while it's in Public Preview.
Add your <openshift-pull-secret>
to the ServiceAccount
definitions in the Kubernetes Operator YAML before installing it.
# 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>
To learn more, see the registry.imagePullSecrets
setting in the
Helm installation settings.
Use the MongoDB Helm Charts for Kubernetes.
You can install the Kubernetes Operator with Helm 3.
Add the MongoDB Helm Charts for Kubernetes repository to Helm.
helm repo add mongodb https://mongodb.github.io/helm-charts
Install the Kubernetes Operator using helm
.
Install MongoDB Helm Charts for Kubernetes:
helm install enterprise-operator mongodb/enterprise-operator \ --values https://raw.githubusercontent.com/mongodb/helm-charts/main/charts/enterprise-operator/values-openshift.yaml
Use the values-openshift.yaml settings. To learn about optional Kubernetes Operator installation settings, see Operator Helm Installation Settings.
Note
To enable the Public Preview of static containers, which improve and simplify security, see Static Containers (Public Preview). We don't recommend using this feature in production while it's in Public Preview.
Install a Specific Daily Build with Helm
MongoDB rebuilds Kubernetes Operator images every day to integrate the latest security and OS updates.
By default, helm
installs the latest build for the version of
the Kubernetes Operator you specify.
To install an earlier build, specify the build ID as a parameter with
--set build=<build-id>
. Build IDs are always in the format
-b<YYYYMMDD>T000000Z
, where <YYYYMMDD>
is the date that the
build you want to use was created.
Example
This example shows how to install the Kubernetes Operator with the latest image:
helm install enterprise-operator mongodb/enterprise-operator
This example shows how to install the Kubernetes Operator with the image created at midnight on February 5th, 2021:
helm install enterprise-operator mongodb/enterprise-operator \ --set build=-b20210205T000000Z
Note
MongoDB recommends using the default (latest) build.
Verify the Installation
To verify that the Kubernetes Operator installed correctly, run the following command and verify the output:
kubectl describe deployments mongodb-enterprise-operator -n <metadata.namespace>
oc describe deployments mongodb-enterprise-operator -n <metadata.namespace>
By default, deployments exist in the mongodb
namespace. If the
following error message appears, ensure you use the correct
namespace:
Error from server (NotFound): deployments.apps "mongodb-enterprise-operator" not found
To troubleshoot your Kubernetes Operator, see Review Logs from the Kubernetes Operator and other troubleshooting topics.
Important
If you need to remove the Kubernetes Operator or the namespace, you first must remove MongoDB resources.
Next Steps
After installing the MongoDB Enterprise Kubernetes Operator, you can: