Para agentes de IA: hay un índice de documentación disponible en https://www.mongodb.com/es/docs/llms.txt — versiones en markdown de todas las páginas están disponibles agregando .md a cualquier ruta URL.

GKE Clusters

Kubernetes no es específico de ningún proveedor; sin embargo, con el fin de proporcionar instrucciones explícitas y completas para implementar todos los elementos de una implementación de Kubernetes Operator de múltiples clústeres, esta sección le guiará a través del proceso de implementar múltiples clústeres de Kubernetes en GCP específicamente.

Antes de comenzar, realice las siguientes acciones:

  • Crea una cuenta de GCP.

  • Prepara un proyecto GCP para que puedas utilizarlo para crear clústeres de GKE (Google Kubernetes Engine).

  • Instala GCP CLI.

  • Autenticarse con el comando gcloud auth login.

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

# GCP project name - this is the only parameter that is mandatory to change hereexport MDB_GKE_PROJECT="${MDB_GKE_PROJECT:="### Set your GKE project name here ###"}" # Adjust the values for each Kubernetes cluster in your deployment.# The deployment script references the following variables to get values for each cluster.export K8S_CLUSTER_0="k8s-mdb-0${K8S_CLUSTER_SUFFIX:-""}"export K8S_CLUSTER_0_ZONE="europe-central2-a"export K8S_CLUSTER_0_NUMBER_OF_NODES=3export K8S_CLUSTER_0_MACHINE_TYPE="e2-standard-4"export K8S_CLUSTER_0_CONTEXT_NAME="gke_${MDB_GKE_PROJECT}_${K8S_CLUSTER_0_ZONE}_${K8S_CLUSTER_0}" export K8S_CLUSTER_1="k8s-mdb-1${K8S_CLUSTER_SUFFIX:-""}"export K8S_CLUSTER_1_ZONE="europe-central2-b"export K8S_CLUSTER_1_NUMBER_OF_NODES=3export K8S_CLUSTER_1_MACHINE_TYPE="e2-standard-4"export K8S_CLUSTER_1_CONTEXT_NAME="gke_${MDB_GKE_PROJECT}_${K8S_CLUSTER_1_ZONE}_${K8S_CLUSTER_1}" export K8S_CLUSTER_2="k8s-mdb-2${K8S_CLUSTER_SUFFIX:-""}"export K8S_CLUSTER_2_ZONE="europe-central2-c"export K8S_CLUSTER_2_NUMBER_OF_NODES=1export K8S_CLUSTER_2_MACHINE_TYPE="e2-standard-4"export K8S_CLUSTER_2_CONTEXT_NAME="gke_${MDB_GKE_PROJECT}_${K8S_CLUSTER_2_ZONE}_${K8S_CLUSTER_2}" # Preemptible nodes disabled — caused random mid-test evictions in CI.# export GKE_SPOT_INSTANCES_SWITCH="--preemptible"

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

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

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

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

Obtén credenciales y guarda contextos en el archivo kubeconfig actual. Por defecto, este archivo se encuentra en el directorio ~/.kube/config y es referenciado por la variable de entorno $KUBECONFIG.

gcloud container clusters get-credentials "${K8S_CLUSTER_0}" --zone="${K8S_CLUSTER_0_ZONE}"gcloud container clusters get-credentials "${K8S_CLUSTER_1}" --zone="${K8S_CLUSTER_1_ZONE}"gcloud 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
echo "Nodes in cluster ${K8S_CLUSTER_0_CONTEXT_NAME}"kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" get nodesecho; echo "Nodes in cluster ${K8S_CLUSTER_1_CONTEXT_NAME}"kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" get nodesecho; echo "Nodes in cluster ${K8S_CLUSTER_2_CONTEXT_NAME}"kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" get nodes
Nodes in cluster gke_scratch-kubernetes-team_europe-central2-a_k8s-mdb-0-cabcbfd835d45fd33bNAME STATUS ROLES AGE VERSIONgke-k8s-mdb-0-cabcbfd835-default-pool-41737e6e-52hc Ready <none> 112s v1.36.4-gke.1391002gke-k8s-mdb-0-cabcbfd835-default-pool-41737e6e-7pds Ready <none> 113s v1.36.4-gke.1391002gke-k8s-mdb-0-cabcbfd835-default-pool-41737e6e-k76f Ready <none> 113s v1.36.4-gke.1391002 Nodes in cluster gke_scratch-kubernetes-team_europe-central2-b_k8s-mdb-1-cabcbfd835d45fd33bNAME STATUS ROLES AGE VERSIONgke-k8s-mdb-1-cabcbfd835-default-pool-a593e388-0m6k Ready <none> 36s v1.36.4-gke.1391002gke-k8s-mdb-1-cabcbfd835-default-pool-a593e388-5zq5 Ready <none> 32s v1.36.4-gke.1391002gke-k8s-mdb-1-cabcbfd835-default-pool-a593e388-zppj Ready <none> 31s v1.36.4-gke.1391002 Nodes in cluster gke_scratch-kubernetes-team_europe-central2-c_k8s-mdb-2-cabcbfd835d45fd33bNAME STATUS ROLES AGE VERSIONgke-k8s-mdb-2-cabcbfd835-default-pool-4a9f72a1-hn1q Ready <none> 44s v1.36.4-gke.1495002