Kubernetes 벤더 에 따라 달라지지 않습니다. 그러나 멀티 클러스터 Kubernetes Operator 구현 의 모든 요소를 배포하기 위한 명시적이고 완전한 지침을 제공하기 위해 이 섹션에서는 특히 GCP 에 여러 Kubernetes 클러스터를 배포하는 프로세스 안내합니다.
전제 조건
시작하기 전에 다음 작업을 수행합니다.
GCP 계정을 만듭니다.
GKE(Google Kubernetes Engine) 클러스터를 만드는데 사용할 수 있도록 GCP 프로젝트 준비합니다.
GCP CLI설치합니다.
필요에 따라 업데이트하고 다음
env_variables.sh
파일 에 정의된 환경 변수를 설정하다 .
1 # GCP project name - this is the only parameter that is mandatory to change here 2 export 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. 6 export K8S_CLUSTER_0="k8s-mdb-0${K8S_CLUSTER_SUFFIX:-""}" 7 export K8S_CLUSTER_0_ZONE="europe-central2-a" 8 export K8S_CLUSTER_0_NUMBER_OF_NODES=3 9 export K8S_CLUSTER_0_MACHINE_TYPE="e2-standard-4" 10 export K8S_CLUSTER_0_CONTEXT_NAME="gke_${MDB_GKE_PROJECT}_${K8S_CLUSTER_0_ZONE}_${K8S_CLUSTER_0}" 11 12 export K8S_CLUSTER_1="k8s-mdb-1${K8S_CLUSTER_SUFFIX:-""}" 13 export K8S_CLUSTER_1_ZONE="europe-central2-b" 14 export K8S_CLUSTER_1_NUMBER_OF_NODES=3 15 export K8S_CLUSTER_1_MACHINE_TYPE="e2-standard-4" 16 export K8S_CLUSTER_1_CONTEXT_NAME="gke_${MDB_GKE_PROJECT}_${K8S_CLUSTER_1_ZONE}_${K8S_CLUSTER_1}" 17 18 export K8S_CLUSTER_2="k8s-mdb-2${K8S_CLUSTER_SUFFIX:-""}" 19 export K8S_CLUSTER_2_ZONE="europe-central2-c" 20 export K8S_CLUSTER_2_NUMBER_OF_NODES=1 21 export K8S_CLUSTER_2_MACHINE_TYPE="e2-standard-4" 22 export 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. 26 export GKE_SPOT_INSTANCES_SWITCH="--preemptible"
소스 코드
절차
2
Kubernetes 클러스터를 생성합니다.
3개의 GKE(Google Kubernetes Engine) 클러스터를 만듭니다. Kubernetes Operator는 이러한 클러스터 중 하나에 배포되고 MongoDB 사용자 지정 리소스는 모든 클러스터에 배포되며 Kubernetes Operator가 managed .
1 gcloud 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:-""}"
1 gcloud 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:-""}"
1 gcloud 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
파일에 자격 증명 저장합니다.
자격 증명 얻고 현재 kubeconfig
파일 에 컨텍스트를 저장합니다. 기본값 으로 이 파일 ~/.kube/config
디렉토리 에 있으며 $KUBECONFIG
환경 변수에의해 참조됩니다.
1 gcloud container clusters get-credentials "${K8S_CLUSTER_0}" --zone="${K8S_CLUSTER_0_ZONE}" 2 gcloud container clusters get-credentials "${K8S_CLUSTER_1}" --zone="${K8S_CLUSTER_1_ZONE}" 3 gcloud 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
kubectl
가 Kubernetes 클러스터에 대한 액세스 있는지 확인합니다.
1 echo "Nodes in cluster ${K8S_CLUSTER_0_CONTEXT_NAME}" 2 kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" get nodes 3 echo; echo "Nodes in cluster ${K8S_CLUSTER_1_CONTEXT_NAME}" 4 kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" get nodes 5 echo; echo "Nodes in cluster ${K8S_CLUSTER_2_CONTEXT_NAME}" 6 kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" get nodes
1 Nodes in cluster gke_scratch-kubernetes-team_europe-central2-a_k8s-mdb-0-682f2df6e1745e000788a1d5-19985 2 NAME STATUS ROLES AGE VERSION 3 gke-k8s-mdb-0-682f2df6e1-default-pool-68d97b7f-fct9 Ready <none> 2m20s v1.32.3-gke.1785003 4 gke-k8s-mdb-0-682f2df6e1-default-pool-68d97b7f-k9td Ready <none> 2m20s v1.32.3-gke.1785003 5 gke-k8s-mdb-0-682f2df6e1-default-pool-68d97b7f-pwsw Ready <none> 2m19s v1.32.3-gke.1785003 6 7 Nodes in cluster gke_scratch-kubernetes-team_europe-central2-b_k8s-mdb-1-682f2df6e1745e000788a1d5-19985 8 NAME STATUS ROLES AGE VERSION 9 gke-k8s-mdb-1-682f2df6e1-default-pool-0f84fbc8-1b4j Ready <none> 32s v1.32.3-gke.1785003 10 gke-k8s-mdb-1-682f2df6e1-default-pool-0f84fbc8-fn7x Ready <none> 32s v1.32.3-gke.1785003 11 gke-k8s-mdb-1-682f2df6e1-default-pool-0f84fbc8-k4hc Ready <none> 32s v1.32.3-gke.1785003 12 13 Nodes in cluster gke_scratch-kubernetes-team_europe-central2-c_k8s-mdb-2-682f2df6e1745e000788a1d5-19985 14 NAME STATUS ROLES AGE VERSION 15 gke-k8s-mdb-2-682f2df6e1-default-pool-ff13f41c-m4f9 Ready <none> 4m6s v1.32.3-gke.1785003