For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Install the MongoDB Controllers for Kubernetes Operator

Before you install the Kubernetes Operator, make sure you plan for your installation:

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.

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-kubernetes.yaml. You must also update the subjects[0].namespace value in every RoleBinding and ClusterRoleBinding in the same file. If you omit this value, the bindings look for the ServiceAccount in the default mongodb namespace and can't find it:

---
apiVersion: v1
kind: ServiceAccount
metadata:
name: mongodb-kubernetes-operator
namespace: production
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: mongodb-kubernetes-operator
namespace: production
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: mongodb-kubernetes-operator
subjects:
- kind: ServiceAccount
name: mongodb-kubernetes-operator
namespace: production
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-kubernetes-operator
namespace: production
---
# Example truncated
---
...
1

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. To learn more, see Preview Features.

2

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-kubernetes/1.1.0/public/mongodb-kubernetes.yaml
3

Populate the <version> placeholder and run the following kubectl command to deploy your chosen version of the CRDs to your Kubernetes cluster:

kubectl apply -f https://raw.githubusercontent.com/mongodb/mongodb-kubernetes/1.1.0/public/crds.yaml

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-kubernetes-openshift.yaml. You must also update the subjects[0].namespace value in every RoleBinding and ClusterRoleBinding in the same file. If you omit this value, the bindings look for the ServiceAccount in the default mongodb namespace and can't find it:

---
apiVersion: v1
kind: ServiceAccount
metadata:
name: mongodb-kubernetes-operator
namespace: production
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: mongodb-kubernetes-operator
namespace: production
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: mongodb-kubernetes-operator
subjects:
- kind: ServiceAccount
name: mongodb-kubernetes-operator
namespace: production
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-kubernetes-operator
namespace: production
---
# Example truncated
---
...
1

Invoke the following git commands:

git clone https://github.com/mongodb/mongodb-kubernetes.git
cd mongodb-kubernetes
git checkout 1.1.0
2

For example, if you cloned the repository in your home directory, run:

cd ~/mongodb-kubernetes
3

Invoke the following oc command:

oc apply -f crds.yaml
4

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. To learn more, see Preview Features.

5
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: enterprise-operator
namespace: mongodb
imagePullSecrets:
- name: <openshift-pull-secret>
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: mongodb-kubernetes-appdb
namespace: mongodb
imagePullSecrets:
- name: <openshift-pull-secret>
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: mongodb-kubernetes-database-pods
namespace: mongodb
imagePullSecrets:
- name: <openshift-pull-secret>

To learn more, see the registry.imagePullSecrets setting in the Helm installation settings.

6

Invoke the following oc command:

oc apply -f mongodb-kubernetes-openshift.yaml

To verify that the Kubernetes Operator installed correctly, run the following command and verify the output:

kubectl describe deployments mongodb-kubernetes-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-kubernetes-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.

After installing the MongoDB Controllers for Kubernetes Operator, you can: