Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs Menu
Docs Home
/
엔터프라이즈 Kubernetes 운영자
/ /

멀티 클러스터 ReplicaSets

다중 Kubernetes 클러스터 MongoDB 배포를 사용하면 여러 지리적 리전에 걸쳐 있는 글로벌 클러스터에 MongoDB 인스턴스를 추가하여 데이터의 가용성과 글로벌 배포를 높일 수 있습니다.

다음 절차를 시작하기 전에 다음 조치를 수행하세요.

  • kubectl를 설치합니다.

  • Mongosh설치

  • GKE 클러스터 절차 또는 이에 상응하는 절차를 완료합니다.

  • TLS 인증서 절차 또는 이에 상응하는 절차를 완료합니다.

  • Istio 서비스 메시 절차 또는 이에 상응하는 절차를 완료합니다.

  • MongoDB 연산자 배포 절차를 완료합니다.

  • 멀티 클러스터 MongoDB Ops Manager 절차 절차를 완료합니다. MongoDB Ops Manager 대신 Cloud Manager 사용하는 경우 이 단계를 건너뛸 수 있습니다.

  • 다음과 같이 필수 환경 변수를 설정합니다.

# This script builds on top of the environment configured in the setup guides.
# It depends (uses) the following env variables defined there to work correctly.
# If you don't use the setup guide to bootstrap the environment, then define them here.
# ${K8S_CLUSTER_0_CONTEXT_NAME}
# ${K8S_CLUSTER_1_CONTEXT_NAME}
# ${K8S_CLUSTER_2_CONTEXT_NAME}
# ${MDB_NAMESPACE}
export RESOURCE_NAME=mdb
export MONGODB_VERSION=8.0.5

포함된 모든 소스 코드 MongoDB Kubernetes Operator 리포지토리 에서 찾을 수 있습니다.

1

다음 스크립트실행하여 인증서 발급자에 필요한 CA 인증서를 생성합니다.

1kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" -f - <<EOF
2apiVersion: cert-manager.io/v1
3kind: Certificate
4metadata:
5 name: mdb-cert
6spec:
7 dnsNames:
8 - "*.${MDB_NAMESPACE}.svc.cluster.local"
9 duration: 240h0m0s
10 issuerRef:
11 name: my-ca-issuer
12 kind: ClusterIssuer
13 renewBefore: 120h0m0s
14 secretName: cert-prefix-mdb-cert
15 usages:
16 - server auth
17 - client auth
18EOF
2

Set spec.credentials, spec.opsManager.configMapRef.name, which you defined in the Multi-Cluster Sharded Cluster procedure; define your security settings and deploy the MongoDBMultiCluster resource. In the following code sample, duplicateServiceObjects is set to false to enable DNS proxying in Istio.

참고

이 튜토리얼에서는 Istio 서비스 메시로 cluster 간 DNS 확인을 활성화하기 위해 각 Kubernetes Pod당 단일 ClusterIP 주소를 사용하여 service 객체를 생성합니다.

1kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" -f - <<EOF
2apiVersion: mongodb.com/v1
3kind: MongoDBMultiCluster
4metadata:
5 name: ${RESOURCE_NAME}
6spec:
7 type: ReplicaSet
8 version: ${MONGODB_VERSION}
9 opsManager:
10 configMapRef:
11 name: mdb-org-project-config
12 credentials: mdb-org-owner-credentials
13 duplicateServiceObjects: false
14 persistent: true
15 externalAccess: {}
16 security:
17 certsSecretPrefix: cert-prefix
18 tls:
19 ca: ca-issuer
20 authentication:
21 enabled: true
22 modes: ["SCRAM"]
23 clusterSpecList:
24 - clusterName: ${K8S_CLUSTER_0_CONTEXT_NAME}
25 members: 2
26 - clusterName: ${K8S_CLUSTER_1_CONTEXT_NAME}
27 members: 1
28 - clusterName: ${K8S_CLUSTER_2_CONTEXT_NAME}
29 members: 2
30EOF
3

다음 명령을 실행하여 MongoDBMultiCluster 리소스 실행 중인지 확인합니다.

1echo; echo "Waiting for MongoDB to reach Running phase..."
2kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" wait --for=jsonpath='{.status.phase}'=Running "mdbmc/${RESOURCE_NAME}" --timeout=900s
3echo; echo "Pods running in cluster ${K8S_CLUSTER_0_CONTEXT_NAME}"
4kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" get pods
5echo; echo "Pods running in cluster ${K8S_CLUSTER_1_CONTEXT_NAME}"
6kubectl --context "${K8S_CLUSTER_1_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" get pods
7echo; echo "Pods running in cluster ${K8S_CLUSTER_2_CONTEXT_NAME}"
8kubectl --context "${K8S_CLUSTER_2_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" get pods
4

다음 명령을 실행하여 MongoDB 사용자와 비밀번호를 생성합니다. 배포서버에 강력한 비밀번호를 사용하세요.

1kubectl apply --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" -f - <<EOF
2apiVersion: v1
3kind: Secret
4metadata:
5 name: rs-user-password
6type: Opaque
7stringData:
8 password: password
9---
10apiVersion: mongodb.com/v1
11kind: MongoDBUser
12metadata:
13 name: rs-user
14spec:
15 passwordSecretKeyRef:
16 name: rs-user-password
17 key: password
18 username: "rs-user"
19 db: "admin"
20 mongodbResourceRef:
21 name: ${RESOURCE_NAME}
22 roles:
23 - db: "admin"
24 name: "root"
25EOF
26
27kubectl --context "${K8S_CLUSTER_0_CONTEXT_NAME}" wait --for=jsonpath='{.status.phase}'=Updated -n "${MDB_NAMESPACE}" mdbu/rs-user
5

mongosh 다음 명령을 실행하여 실행 MongoDB 인스턴스 에 액세스 할 수 있는지 확인합니다.

1# Load Balancers sometimes take longer to get an IP assigned, we need to retry
2while [ -z "$(kubectl get --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" svc "${RESOURCE_NAME}-0-0-svc-external" -o=jsonpath="{.status.loadBalancer.ingress[0].ip}")" ]
3do
4 sleep 5
5done
6
7external_ip="$(kubectl get --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" svc "${RESOURCE_NAME}-0-0-svc-external" -o=jsonpath="{.status.loadBalancer.ingress[0].ip}")"
8
9mkdir -p certs
10kubectl get --context "${K8S_CLUSTER_0_CONTEXT_NAME}" -n "${MDB_NAMESPACE}" cm/ca-issuer -o=jsonpath='{.data.ca-pem}' > certs/ca.crt
11
12mongosh --host "${external_ip}" --username rs-user --password password --tls --tlsCAFile certs/ca.crt --tlsAllowInvalidHostnames --eval "db.runCommand({connectionStatus : 1})"
{
authInfo: {
authenticatedUsers: [ { user: 'rs-user', db: 'admin' } ],
authenticatedUserRoles: [ { role: 'root', db: 'admin' } ]
},
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1741701953, i: 1 }),
signature: {
hash: Binary.createFromBase64('uhYReuUiWNWP6m1lZ5umgDVgO48=', 0),
keyId: Long('7480552820140146693')
}
},
operationTime: Timestamp({ t: 1741701953, i: 1 })
}

이 페이지의 내용