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

Deploy the Kubernetes Operator Without a Service Mesh

In order to deploy multiple instances of MongoDB resources across multiple Kubernetes clusters, you first need to deploy the Kubernetes Operator to one of your Kubernetes clusters. Once the Kubernetes Operator is deployed to your operator Kubernetes cluster, you can then create and manage all of your MongoDB resources across all of your Kubernetes clusters by applying updates to your operator Kubernetes cluster.

Before you begin the following procedure, perform the following actions:

  • Install kubectl.

  • Complete the GKE Clusters procedure or the equivalent.

  • Complete the TLS Certificates procedure or the equivalent.

  • Complete the Istio Service mesh procedure or the equivalent.

  • Install the kubectl mongodb plugin. To install the kubectl mongodb plugin:

    1

    Download your desired Kubernetes Operator package version from the Release Page of the MongoDB Controllers for Kubernetes Operator Repository.

    The package's name uses this pattern: kubectl-mongodb_{{ .Version }}_{{ .Os }}_{{ .Arch }}.tar.gz.

    Use one of the following packages:

    • kubectl-mongodb_{{ .Version }}_darwin_amd64.tar.gz

    • kubectl-mongodb_{{ .Version }}_darwin_arm64.tar.gz

    • kubectl-mongodb_{{ .Version }}_linux_amd64.tar.gz

    • kubectl-mongodb_{{ .Version }}_linux_arm64.tar.gz

    2

    Unpack the package, as in the following example:

    tar -zxvf kubectl-mongodb_<version>_darwin_amd64.tar.gz
    3

    Find the kubectl-mongodb binary in the unpacked directory and move it to its desired destination, inside the PATH for the Kubernetes Operator user, as shown in the following example:

    mv kubectl-mongodb /usr/local/bin/kubectl-mongodb

    Now you can run the kubectl mongodb plugin using the following commands:

    kubectl mongodb multicluster setup
    kubectl mongodb multicluster recover

    To learn more about the supported flags, see the MongoDB kubectl plugin Reference.

  • Update as needed and set the environment variables defined in the following env_variables.sh file.

    1# Namespace in which Ops Manager and AppDB will be deployed
    2export OM_NAMESPACE="mongodb-om"
    3# Namespace in which the operator will be installed
    4export OPERATOR_NAMESPACE="mongodb-operator"
    5# Namespace in which MongoDB resources will be deployed
    6export MDB_NAMESPACE="mongodb"
    7
    8# comma-separated key=value pairs for additional parameters passed to the helm-chart installing the operator
    9export OPERATOR_ADDITIONAL_HELM_VALUES="${OPERATOR_ADDITIONAL_HELM_VALUES:-""}"
    10
    11export OFFICIAL_OPERATOR_HELM_CHART="mongodb/mongodb-kubernetes"
    12export OPERATOR_HELM_CHART="${OPERATOR_HELM_CHART:-${OFFICIAL_OPERATOR_HELM_CHART}}"

You can find all included source code in the MongoDB Kubernetes Operator repository.

1
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" create namespace "${OPERATOR_NAMESPACE}"
kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" create namespace "${OPERATOR_NAMESPACE}"
kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" create namespace "${OPERATOR_NAMESPACE}"
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" create namespace "${OM_NAMESPACE}"
kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" create namespace "${OM_NAMESPACE}"
kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" create namespace "${OM_NAMESPACE}"
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" create namespace "${MDB_NAMESPACE}"
kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" create namespace "${MDB_NAMESPACE}"
kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" create namespace "${MDB_NAMESPACE}"
2
mkdir -p secrets
kubectl create secret generic "image-registries-secret" \
--from-file=.dockerconfigjson="${HOME}/.docker/config.json" --type=kubernetes.io/dockerconfigjson \
--dry-run=client -o yaml > secrets/image-registries-secret.yaml
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${OPERATOR_NAMESPACE}" apply -f secrets/image-registries-secret.yaml
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${OM_NAMESPACE}" apply -f secrets/image-registries-secret.yaml
kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" -n "${OM_NAMESPACE}" apply -f secrets/image-registries-secret.yaml
kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" -n "${OM_NAMESPACE}" apply -f secrets/image-registries-secret.yaml
kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" apply -f secrets/image-registries-secret.yaml
kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" apply -f secrets/image-registries-secret.yaml
kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" apply -f secrets/image-registries-secret.yaml
3

Run the following command to configure your Kubernetes clusters.

1kubectl mongodb multicluster setup \
2 --central-cluster="${K8S_CLUSTER_0_CONTEXT_NAME}" \
3 --member-clusters="${K8S_CLUSTER_0_CONTEXT_NAME},${K8S_CLUSTER_1_CONTEXT_NAME},${K8S_CLUSTER_2_CONTEXT_NAME}" \
4 --member-cluster-namespace="${OM_NAMESPACE}" \
5 --central-cluster-namespace="${OPERATOR_NAMESPACE}" \
6 --create-service-account-secrets \
7 --install-database-roles=true \
8 --image-pull-secrets=image-registries-secret
9
10kubectl mongodb multicluster setup \
11 --central-cluster="${K8S_CLUSTER_0_CONTEXT_NAME}" \
12 --member-clusters="${K8S_CLUSTER_0_CONTEXT_NAME},${K8S_CLUSTER_1_CONTEXT_NAME},${K8S_CLUSTER_2_CONTEXT_NAME}" \
13 --member-cluster-namespace="${MDB_NAMESPACE}" \
14 --central-cluster-namespace="${OPERATOR_NAMESPACE}" \
15 --create-service-account-secrets \
16 --install-database-roles=true \
17 --image-pull-secrets=image-registries-secret
4

Add the MongoDB Helm Charts for Kubernetes repository to Helm.

1helm repo add mongodb https://mongodb.github.io/helm-charts
2helm repo update mongodb
3helm search repo "${OFFICIAL_OPERATOR_HELM_CHART}"
5

Use the MongoDB Helm Charts for Kubernetes to deploy the Kubernetes Operator.

1helm upgrade --install \
2 --debug \
3 --kube-context "${K8S_CLUSTER_0_CONTEXT_NAME}" \
4 mongodb-kubernetes-operator-multi-cluster \
5 "${OPERATOR_HELM_CHART}" \
6 --namespace="${OPERATOR_NAMESPACE}" \
7 --set namespace="${OPERATOR_NAMESPACE}" \
8 --set operator.namespace="${OPERATOR_NAMESPACE}" \
9 --set operator.watchNamespace="${OM_NAMESPACE}\,${MDB_NAMESPACE}" \
10 --set operator.name=mongodb-kubernetes-operator-multi-cluster \
11 --set operator.createOperatorServiceAccount=false \
12 --set operator.createResourcesServiceAccountsAndRoles=false \
13 --set "multiCluster.clusters={${K8S_CLUSTER_0_CONTEXT_NAME},${K8S_CLUSTER_1_CONTEXT_NAME},${K8S_CLUSTER_2_CONTEXT_NAME}}" \
14 --set "${OPERATOR_ADDITIONAL_HELM_VALUES:-"dummy=value"}" \
15 --set operator.env=dev
6
1kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${OPERATOR_NAMESPACE}" rollout status --timeout=2m deployment/mongodb-kubernetes-operator-multi-cluster
2echo "Operator deployment in ${OPERATOR_NAMESPACE} namespace"
3kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${OPERATOR_NAMESPACE}" get deployments
4echo; echo "Operator pod in ${OPERATOR_NAMESPACE} namespace"
5kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${OPERATOR_NAMESPACE}" get pods