- Deploy Multiple Clusters (Beta) >
- Multi-Cluster Quick Start
Multi-Cluster Quick Start¶
On this page
Important
Use the beta release of the multi-cluster deployments only in development environments.
Overview¶
Using multi-cluster deployments, you can deploy MongoDB Enterprise Kubernetes Operator to manage MongoDB deployments that span more than one Kubernetes cluster.
This tutorial demonstrates how you can use the Kubernetes Operator to deploy a MongoDB replica set across three Kubernetes member clusters, using GKE (Google Kubernetes Engine) and Istio service mesh.
The beta release of the multi-cluster deployments offers you different layers of availability, depending on the needs of your enterprise application. You can use this tutorial to deploy:
Single Region, Multi AZ. One or more Kubernetes clusters where each cluster has nodes deployed in different zones in the same region. Such deployments protect MongoDB instances backing your enterprise applications against failures and offer increased availability, disaster recovery, and data distribution within one cloud region.
Multi Region. One or more Kubernetes clusters where you:
- Deploy each cluster in a different region, and
- Within each region, deploy cluster nodes in different availability zones.
Such deployments allow you to add MongoDB instances in global clusters that span multiple geographic regions for increased availability and global distribution of data.
Central Cluster and Member Clusters¶
Istio manages the discovery of MongoDB nodes deployed in different Kubernetes member clusters. Each multi-cluster deployment that uses Istio comprises one Kubernetes central cluster and one or more member clusters.
- Central cluster in Kubernetes contains:
- MongoDB Enterprise Kubernetes Operator
- Ops Manager, if you deploy it with the Kubernetes Operator
- Kubernetes Operator
MongoDBMulti
CustomResource spec for the MongoDB replica set.
- Member clusters in Kubernetes host the MongoDB replica sets.
You can host your application on any of the member clusters inside the Istio service mesh, either on Kubernetes clusters outside of the ones that you deploy with the Kubernetes Operator, or on the member clusters that you deploy as part of this tutorial.
To learn more, see the Multi-Cluster Deployment Architecture.
Services and Tools¶
This tutorial relies on the following services, tools, and their documentation:
- Kubernetes clusters. This tutorial uses GKE (Google Kubernetes Engine) to provision multiple Kubernetes clusters. Each Kubernetes member cluster hosts a MongoDB replica set deployment and represents a data center that serves your application.
- Istio service mesh. This tutorial uses Istio to facilitate DNS resolution for MongoDB replica sets deployed in different Kubernetes clusters.
- MongoDB Enterprise Kubernetes Operator repository with configuration files that the Kubernetes Operator needs to deploy a Kubernetes cluster.
- MongoDB Helm Charts for Kubernetes with charts for multi-cluster deployments.
- Documentation from Istio to Install Multicluster.
- install_istio_separate_network script that is based on Istio documentation and provides an example installation that uses the multi-primary mode on different networks.
- multi-cluster kubeconfig creator
tool that performs the following actions:
- Creates a single
mongodb
namespace in the central cluster and each member cluster. - Creates Service Accounts, Roles, and RoleBindings in the central cluster and each member cluster.
- Puts Service Account token secrets from each member cluster into a
single
kubeconfig
file and saves the file in the central cluster. This enables authorized access from the Kubernetes Operator installed in the central cluster to the member clusters.
- Creates a single
Prerequisites¶
This tutorial requires that you:
Set the environment variables with cluster names and the available GKE zones where you deploy the cluster, as in this example:
Set up GKE (Google Kubernetes Engine) clusters:
Set up your Google Cloud account and the
gcloud
tool, using the Google Kubernetes Engine Quickstart.Create one central cluster and one or more member clusters, specifying the zones, the number of nodes, and the instance types, as in these examples:
Obtain user authentication credentials for the central and member clusters and save the credentials. You will later use these authentication credentials for running
kubectl
commands on these Kubernetes clusters. Run the following commands:Install Istio in a multi-primary mode on different networks, using the install_istio_separate_network script. To learn more, see the Install Multicluster documentation from Istio.
Install Go v1.16 or later.
Procedure¶
Run the multi-cluster kubeconfig creator
tool.¶
By default, the Kubernetes Operator uses the mongodb
namespace.
To simplify your installation, the tool creates one central cluster,
three member clusters, and a namespace labeled mongodb
in each of
the clusters.
Change to the directory to which you cloned the Kubernetes Operator repository, and then to the directory that has the
multi-cluster kubeconfig creator
tool.Run the multi-cluster kubeconfig creator tool:
Set the Istio injection webhook in each member cluster.¶
Run the following command on the central cluster, specifying the context
for each of the member clusters in the deployment. These commands add
the``istio-injection=enabled`` label to the mongodb
namespace on
each member cluster. This label configures Istio’s injection webhook
which enables adding a sidecar to any Pods that you create in this
namespace. To learn more, see Automatic sidecar injection
in the Istio documentation.
Configure kubectl
to use the central cluster’s namespace.¶
If you have not done so already, run the following commands to run
all kubectl
commands on the central cluster in the default
namespace. In the following steps, you will install the Kubernetes Operator
into this namespace.
Add the MongoDB Helm Charts for Kubernetes repository to Helm.¶
Install the MongoDB Enterprise Kubernetes Operator in the central cluster.¶
Use the Helm charts for the Kubernetes Operator and multi-cluster deployments to install Kubernetes Operator for managing your multi-cluster deployment:
Deploy the MongoDB resource.¶
On the central cluster, create a secret so that the Kubernetes Operator can create and update objects in your Ops Manager project. To learn more, see Create Credentials for the Kubernetes Operator.
On the central cluster, create a ConfigMap to link the Kubernetes Operator to your Ops Manager project. To learn more, see Create One Project using a ConfigMap.
On the central cluster, configure the required service accounts for each member cluster:
Set
spec.credentials
andspec.opsManager.configMapRef.name
and deploy the MongoDB resource. In the following code sample,duplicateServiceObjects
is set totrue
to enable DNS proxying in Istio.Note
To enable the cross-cluster DNS resolution by the Istio service mesh, this tutorial creates service objects with a single ClusterIP address per each Kubernetes Pod.
Verify that the MDB resources are running.¶
For member clusters, run the following commands to verify that the MongoDB Pods are in the running state:
In the central cluster, run the following commands to verify that the MongoDBMulti
CustomResource
is in the running state:
Troubleshooting Mutli-Cluster Deployments¶
To troubleshoot your multi-cluster deployments, use the procedures in this section.
Recovering from Cluster Failure¶
This procedure uses the same cluster names as in the Prerequisites.
If the cluster MDB_CLUSTER_1
that holds MongoDB nodes goes down, and
if you provision a new cluster named MDB_CLUSTER_4
instead of
MDB_CLUSTER_1
to hold the new MongoDB nodes, run the
multi-cluster kubeconfig creator
tool with the updated list of member clusters, and then edit the MongoDBMulti
CustomResource spec on the central cluster.
To reconfigure the multi-cluster deployment after a cluster failure, replace the failed cluster with the newly provisioned cluster as follows:
Run the multi-cluster kubeconfig creator tool with the new cluster
MDB_CLUSTER_4
specified in the-member-clusters
flag. This enables the Kubernetes Operator to communicate with the new cluster to schedule MongoDB nodes on it. In the following example,-member-clusters
contains${MDB_CLUSTER_4_FULL_NAME}
.On the central cluster, locate and edit the
MongoDBMulti
CustomResource spec to add the new cluster name to theclusterSpecList
and remove the failed cluster from this list. The resulting list of cluster names should be similar to the following:Restart the Kubernetes Operator Pod. After the restart, the Kubernetes Operator should reconcile the MongoDB deployment on the newly created
MDB_CLUSTER_4
cluster that has been created as a replacement for theMDB_CLUSTER_1
failure. To learn more about resource reconciliation, see Multi-Cluster Deployment Architecture.