Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs Menu
Docs Home
/
Kubernetes Operator 用のMongoDBドライバー
/ /

GKE クラスターの配置

Kubernetesはベンダーに固有ではありません。ただし、 マルチクラスターKubernetes Operator実装のすべての要素を配置するための明示的かつ完全な手順を提供するため、このセクションでは具体的には、複数のKubernetesクラスターを GCPに配置するプロセスについて説明します。

始める前に、次のアクションを実行してください。

  • GCPアカウントの作成。

  • Prepare a GCP project so that you can use it to create GKE (Google Kubernetes Engine) clusters.

  • Install the GCP CLI.

  • Authenticate with the gcloud auth login command.

  • 必要に応じて を更新し、次の 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"

含まれているすべてのソースコードはMongoDB Kubernetes Operatorリポジトリにあります。

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

Create three GKE (Google Kubernetes Engine) clusters. The Kubernetes Operator is deployed to one of these clusters, and MongoDB custom resources are deployed across all clusters, and are managed by the Kubernetes Operator.

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

認証情報を取得し、コンテキストを現在の kubeconfigファイルに保存します。デフォルトでは、このファイルは~/.kube/configディレクトリにあり、$KUBECONFIG 環境変数によって参照されます。

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}"

すべてのkubectlコマンドは、次の変数を使用してこれらのコンテキストを参照します。

  • $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-686cc1e099f9ef000722c191-862
2NAME STATUS ROLES AGE VERSION
3gke-k8s-mdb-0-686cc1e099-default-pool-63c33f99-532x Ready <none> 3m7s v1.32.4-gke.1415000
4gke-k8s-mdb-0-686cc1e099-default-pool-63c33f99-fs12 Ready <none> 3m7s v1.32.4-gke.1415000
5gke-k8s-mdb-0-686cc1e099-default-pool-63c33f99-hghj Ready <none> 3m7s v1.32.4-gke.1415000
6
7Nodes in cluster gke_scratch-kubernetes-team_europe-central2-b_k8s-mdb-1-686cc1e099f9ef000722c191-862
8NAME STATUS ROLES AGE VERSION
9gke-k8s-mdb-1-686cc1e099-default-pool-93d5418d-712x Ready <none> 57s v1.32.4-gke.1415000
10gke-k8s-mdb-1-686cc1e099-default-pool-93d5418d-hpcc Ready <none> 58s v1.32.4-gke.1415000
11gke-k8s-mdb-1-686cc1e099-default-pool-93d5418d-wg14 Ready <none> 61s v1.32.4-gke.1415000
12
13Nodes in cluster gke_scratch-kubernetes-team_europe-central2-c_k8s-mdb-2-686cc1e099f9ef000722c191-862
14NAME STATUS ROLES AGE VERSION
15gke-k8s-mdb-2-686cc1e099-default-pool-d128293d-tng2 Ready <none> 3m12s v1.32.4-gke.1415000

戻る

サービス メッシュのないマルチクラスター アーキテクチャ

項目一覧