Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /

GKE Clusters

Kubernetes no es específico de ningún proveedor; sin embargo, a fin de proporcionar instrucciones explícitas y completas para implementar todos los elementos de una implementación multi-clúster de un operador de Kubernetes, esta sección lo guiará mediante el proceso de implementación de múltiples clústeres de Kubernetes en GCP specifically.

Antes de comenzar, realice las siguientes acciones:

  • Crea una cuenta de GCP.

  • Prepare un proyecto de GCP para que pueda usarlo para crear GKE (Google Kubernetes Engine) clústeres.

  • Instala GCP CLI.

  • Autenticarse con el gcloud auth login dominio.

  • Actualiza según sea necesario y configura las variables de entorno definidas en el siguiente archivo env_variables.sh.

1# GCP project name - this is the only parameter that is mandatory to change here
2export MDB_GKE_PROJECT="${MDB_GKE_PROJECT:="### Set your GKE project name here ###"}"
3
4# Adjust the values for each Kubernetes cluster in your deployment.
5# The deployment script references the following variables to get values for each cluster.
6export K8S_CLUSTER_0="k8s-mdb-0${K8S_CLUSTER_SUFFIX:-""}"
7export K8S_CLUSTER_0_ZONE="europe-central2-a"
8export K8S_CLUSTER_0_NUMBER_OF_NODES=3
9export K8S_CLUSTER_0_MACHINE_TYPE="e2-standard-4"
10export K8S_CLUSTER_0_CONTEXT_NAME="gke_${MDB_GKE_PROJECT}_${K8S_CLUSTER_0_ZONE}_${K8S_CLUSTER_0}"
11
12export K8S_CLUSTER_1="k8s-mdb-1${K8S_CLUSTER_SUFFIX:-""}"
13export K8S_CLUSTER_1_ZONE="europe-central2-b"
14export K8S_CLUSTER_1_NUMBER_OF_NODES=3
15export K8S_CLUSTER_1_MACHINE_TYPE="e2-standard-4"
16export K8S_CLUSTER_1_CONTEXT_NAME="gke_${MDB_GKE_PROJECT}_${K8S_CLUSTER_1_ZONE}_${K8S_CLUSTER_1}"
17
18export K8S_CLUSTER_2="k8s-mdb-2${K8S_CLUSTER_SUFFIX:-""}"
19export K8S_CLUSTER_2_ZONE="europe-central2-c"
20export K8S_CLUSTER_2_NUMBER_OF_NODES=1
21export K8S_CLUSTER_2_MACHINE_TYPE="e2-standard-4"
22export K8S_CLUSTER_2_CONTEXT_NAME="gke_${MDB_GKE_PROJECT}_${K8S_CLUSTER_2_ZONE}_${K8S_CLUSTER_2}"
23
24# Comment out the following line so that the script does not create preemptible nodes.
25# DO NOT USE preemptible nodes in production.
26export GKE_SPOT_INSTANCES_SWITCH="--preemptible"

Se puede encontrar todo el código fuente incluido en el repositorio de MongoDB Kubernetes operador.

1
1gcloud config set project "${MDB_GKE_PROJECT}"
2

Crea tres clústeres de GKE (Google Kubernetes Engine):

1gcloud container clusters create "${K8S_CLUSTER_0}" \
2 --zone="${K8S_CLUSTER_0_ZONE}" \
3 --num-nodes="${K8S_CLUSTER_0_NUMBER_OF_NODES}" \
4 --machine-type "${K8S_CLUSTER_0_MACHINE_TYPE}" \
5 --tags=mongodb \
6 "${GKE_SPOT_INSTANCES_SWITCH:-""}"
1gcloud container clusters create "${K8S_CLUSTER_1}" \
2 --zone="${K8S_CLUSTER_1_ZONE}" \
3 --num-nodes="${K8S_CLUSTER_1_NUMBER_OF_NODES}" \
4 --machine-type "${K8S_CLUSTER_1_MACHINE_TYPE}" \
5 --tags=mongodb \
6 "${GKE_SPOT_INSTANCES_SWITCH:-""}"
1gcloud container clusters create "${K8S_CLUSTER_2}" \
2 --zone="${K8S_CLUSTER_2_ZONE}" \
3 --num-nodes="${K8S_CLUSTER_2_NUMBER_OF_NODES}" \
4 --machine-type "${K8S_CLUSTER_2_MACHINE_TYPE}" \
5 --tags=mongodb \
6 "${GKE_SPOT_INSTANCES_SWITCH:-""}"
3

Obtener credenciales y guardar contextos en el archivo kubeconfig actual. De forma predeterminada, este archivo se encuentra en el directorio ~/.kube/config y se referencia mediante el directorio $KUBECONFIG. variable de entorno.

1gcloud container clusters get-credentials "${K8S_CLUSTER_0}" --zone="${K8S_CLUSTER_0_ZONE}"
2gcloud container clusters get-credentials "${K8S_CLUSTER_1}" --zone="${K8S_CLUSTER_1_ZONE}"
3gcloud container clusters get-credentials "${K8S_CLUSTER_2}" --zone="${K8S_CLUSTER_2_ZONE}"

Todos los comandos de kubectl hacen referencia a estos contextos usando las siguientes variables:

  • $K8S_CLUSTER_0_CONTEXT_NAME

  • $K8S_CLUSTER_1_CONTEXT_NAME

  • $K8S_CLUSTER_2_CONTEXT_NAME

4
1echo "Nodes in cluster ${K8S_CLUSTER_0_CONTEXT_NAME}"
2kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" get nodes
3echo; echo "Nodes in cluster ${K8S_CLUSTER_1_CONTEXT_NAME}"
4kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" get nodes
5echo; echo "Nodes in cluster ${K8S_CLUSTER_2_CONTEXT_NAME}"
6kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" get nodes
1Nodes in cluster gke_scratch-kubernetes-team_europe-central2-a_k8s-mdb-0-682f2df6e1745e000788a1d5-19985
2NAME STATUS ROLES AGE VERSION
3gke-k8s-mdb-0-682f2df6e1-default-pool-68d97b7f-fct9 Ready <none> 2m20s v1.32.3-gke.1785003
4gke-k8s-mdb-0-682f2df6e1-default-pool-68d97b7f-k9td Ready <none> 2m20s v1.32.3-gke.1785003
5gke-k8s-mdb-0-682f2df6e1-default-pool-68d97b7f-pwsw Ready <none> 2m19s v1.32.3-gke.1785003
6
7Nodes in cluster gke_scratch-kubernetes-team_europe-central2-b_k8s-mdb-1-682f2df6e1745e000788a1d5-19985
8NAME STATUS ROLES AGE VERSION
9gke-k8s-mdb-1-682f2df6e1-default-pool-0f84fbc8-1b4j Ready <none> 32s v1.32.3-gke.1785003
10gke-k8s-mdb-1-682f2df6e1-default-pool-0f84fbc8-fn7x Ready <none> 32s v1.32.3-gke.1785003
11gke-k8s-mdb-1-682f2df6e1-default-pool-0f84fbc8-k4hc Ready <none> 32s v1.32.3-gke.1785003
12
13Nodes in cluster gke_scratch-kubernetes-team_europe-central2-c_k8s-mdb-2-682f2df6e1745e000788a1d5-19985
14NAME STATUS ROLES AGE VERSION
15gke-k8s-mdb-2-682f2df6e1-default-pool-ff13f41c-m4f9 Ready <none> 4m6s v1.32.3-gke.1785003

Volver

Arquitectura multi-clúster

En esta página