Use the quick start to deploy a MongoDB replica set across three Kubernetes member clusters, using GKE (Google Kubernetes Engine) and Istio service mesh.
Before you begin:
Learn about multi-Kubernetes-cluster deployments
Review the list of multi-Kubernetes-cluster services and tools
Complete the prerequisites
Note
The following procedures scope your multi-Kubernetes cluster MongoDB deployment to a single
namespace named mongodb. You can configure your multi-Kubernetes cluster MongoDB deployment to
watch resources in multiple namespaces
or all namespaces.
Prefer to Learn by Watching?
Follow along with this video tutorial walk-through that demonstrates how to create a multi-Kubernetes cluster MongoDB deployment.
Duration: 12 Minutes
Deploying a MongoDB Replica Set across Multiple Kubernetes Clusters
Prerequisites
Before you create a multi-Kubernetes cluster MongoDB deployment using the quick start, complete the following tasks:
Review the General Prerequisites
Ensure you meet the general prerequisite before you proceed. To learn more, see General Prerequisites.
Set Environment Variables and GKE Zones
Set the environment variables with cluster names and the available GKE zones where you deploy the clusters, as in this example:
export MDB_GKE_PROJECT={GKE project name} export MDB_CENTRAL_CLUSTER_ZONE="us-west1-a" export MDB_CLUSTER_1_ZONE="us-west1-b" export MDB_CLUSTER_2_ZONE="us-east1-b" export MDB_CLUSTER_3_ZONE="us-central1-a" export MDB_CENTRAL_CLUSTER_FULL_NAME="gke_${MDB_GKE_PROJECT}_${MDB_CENTRAL_CLUSTER_ZONE}_${MDB_CENTRAL_CLUSTER}" export MDB_CLUSTER_1_FULL_NAME="gke_${MDB_GKE_PROJECT}_${MDB_CLUSTER_1_ZONE}_${MDB_CLUSTER_1}" export MDB_CLUSTER_2_FULL_NAME="gke_${MDB_GKE_PROJECT}_${MDB_CLUSTER_2_ZONE}_${MDB_CLUSTER_2}" export MDB_CLUSTER_3_FULL_NAME="gke_${MDB_GKE_PROJECT}_${MDB_CLUSTER_3_ZONE}_${MDB_CLUSTER_3}"
Set up GKE Clusters
Set up GKE (Google Kubernetes Engine) clusters:
Set up your Google Cloud account.
If you have not done so already, create a Google Cloud project, enable billing on the project, enable the Artifact Registry and GKE APIs, and launch Cloud Shell by following the relevant procedures in the Google Kubernetes Engine Quickstart in the Google Cloud documentation.
Create a operator cluster and member clusters.
Create one operator cluster and one or more member clusters, specifying the GKE zones, the number of nodes, and the instance types, as in these examples:
gcloud container clusters create $MDB_CENTRAL_CLUSTER \ --zone=$MDB_CENTRAL_CLUSTER_ZONE \ --num-nodes=5 \ --machine-type "e2-standard-2"
gcloud container clusters create $MDB_CLUSTER_1 \ --zone=$MDB_CLUSTER_1_ZONE \ --num-nodes=5 \ --machine-type "e2-standard-2"
gcloud container clusters create $MDB_CLUSTER_2 \ --zone=$MDB_CLUSTER_2_ZONE \ --num-nodes=5 \ --machine-type "e2-standard-2"
gcloud container clusters create $MDB_CLUSTER_3 \ --zone=$MDB_CLUSTER_3_ZONE \ --num-nodes=5 \ --machine-type "e2-standard-2"
Obtain User Authentication Credentials for Central and Member Clusters
Obtain user authentication credentials for the central and member Kubernetes
clusters and save the credentials. You will later use these credentials
for running kubectl commands on these clusters.
Run the following commands:
gcloud container clusters get-credentials $MDB_CENTRAL_CLUSTER \ --zone=$MDB_CENTRAL_CLUSTER_ZONE gcloud container clusters get-credentials $MDB_CLUSTER_1 \ --zone=$MDB_CLUSTER_1_ZONE gcloud container clusters get-credentials $MDB_CLUSTER_2 \ --zone=$MDB_CLUSTER_2_ZONE gcloud container clusters get-credentials $MDB_CLUSTER_3 \ --zone=$MDB_CLUSTER_3_ZONE
Deploy a MongoDBMultiCluster Resource
Select the appropriate tab based on whether you want to encrypt replica set connections in your multi-Kubernetes cluster MongoDB deployments using TLS certificates.
Next Steps
After deploying your MongoDB replica set across three Kubernetes member clusters, you can add a database user so you can connect to your MongoDB database. See Manage Database Users.