여러 Kubernetes 클러스터에 MongoDB Sharded Clusters를 배포할 수 있습니다. 멀티 클러스터 기능을 사용하면 다음을 수행할 수 있습니다.
각각 다른 지리적 리전 에 있는 여러 Kubernetes 클러스터에 배포하여 배포서버 의 회복 탄력성 개선합니다.
해당 데이터에 의존하는 애플리케이션 또는 클라이언트에 더 가까운 다양한 Kubernetes 클러스터에 지정된 샤드의 프라이머리 노드를 배포하여 지리적 샤딩 위한 배포서버 구성하고 지연 시간 줄입니다.
성능 향상을 위해 배포서버 조정합니다. 예시 를 들어, 다른 Kubernetes 클러스터의 모든 또는 지정된 샤드에 대해 또는 사용자 지정된 리소스 할당을 사용하여 읽기 전용 분석 노드를 배포 할 수 있습니다.
또한 다양한 수준에서 샤드, mongos 및 config 서버 세부 정보를 구성할 수 있습니다. 즉, 샤드, config 서버 및 mongos 에 대한 기본값 기본 구성을 정의하고 각 Kubernetes 클러스터 에 대해 독립적으로 사용자 지정할 수 있습니다. 또한 특정 요구 사항에 맞게 개별 샤드를 사용자 지정할 수 있습니다.
중요
멀티 클러스터 샤딩된 클러스터 기능을 사용하면 여러 지리적 리전의 여러 Kubernetes 클러스터에 MongoDB 리소스를 배포 수 있습니다. 그러나 이렇게 하면 복제 작업의 지연 시간 이 늘어날 수 있습니다.
멀티 클러스터 샤딩된 클러스터 토폴로지 의 특정 구성 옵션에 대해 자세히 학습 샤딩된 클러스터 참조를 확인하세요.
제한 사항
Kubernetes 시크릿 인젝션에는 Hashicorp Vault 지원 사용할 수 없습니다.
멤버 클러스터 에 장애가 발생하면 먼저 장애가 발생한 클러스터를 0으로 수동으로 확장하다 하여 비정상 프로세스를 제거 해야 합니다. 그런 다음 중앙 클러스터 에 배포된 CRD 리소스 업데이트하여 나머지 정상 Kubernetes 클러스터에 수동으로 리소스를 재배포할 수 있습니다. 자세한 학습은 재해 복구 를 참조하세요.
전제 조건
멀티 클러스터 배포서버 위해 Kubernetes 클러스터를 준비합니다.
Kubernetes 클러스터 중 하나에 멀티 클러스터 배포를 위해 Kubernetes Operator를 설치하고 구성합니다.
옵션 1: 노드 클러스터 전체에 서비스 메시를 배포합니다. 자세한 절차는 MongoDB Ops Manager 멀티 클러스터 배포 가이드의 1 ~ 6 단계에서 찾을 수 있습니다. 이 절차는 독단적인 절차이며 가능한 많은 구성 중 하나에 불과합니다.
옵션: 비서비스 2메시 배포서버 위해 Kubernetes 클러스터를 구성합니다.
Ops 관리자 또는 Cloud Manager 인스턴스와 MongoDB 조직 및 프로젝트에 대한 자격 증명 생성 합니다.
샤드 클러스터 배포 예시
아래 예시 에서는 중앙 클러스터 에 적용하는 경우 다음과 같이 구성된 3 샤드를 사용하여 샤딩된 MongoDB cluster 배포합니다.
각 샤드 에는 모든 Kubernetes 클러스터에 분산된 노드가 있습니다( 클러스터 당 1 노드 ).
기본값 으로 각 샤드의 복제본 세트는 다음과 같습니다.
3 클러스터에 배포된 총 3 투표 멤버가 있음(각 클러스터 의 1 노드 )
프라이머리 샤드
kind-e2e-cluster-1에 있는 것이 좋습니다.
샤드
sc-0에shardOverride를 사용하여 기본값 (spec.shard에 지정됨)을 다음과 같이 변경합니다.총 5 명의 멤버
2 멤버
kind-e2e-cluster-12 멤버
kind-e2e-cluster-21 멤버
kind-e2e-cluster-3가능하면 프라이머리 샤드 다음 위치에 있는 것이 좋습니다.
kind-e2e-cluster-2
에 정의된 대로 모든 클러스터의 모든 샤드에 대한 사용자 지정 기본값 저장 설정
spec.shardPodSpec3 멤버가 있는 config 서버 복제본 세트, 각 클러스터 에 1 멤버가 있음
총 3 mongos 인스턴스 배포, 각 클러스터 에 1 인스턴스
기본값 구성은 3개의 샤드로 구성되며, 각 샤드에는 3개의 클러스터 각각에 하나의 멤버가 있으며 샤드 당 총 3개의 멤버가 있습니다. 그러나 재정의에서는 기본값 에 따라 sc-0 샤드 클러스터 1에 2개, 클러스터 2에 2개, 클러스터 3 에 여전히 하나의 샤드 를 포함하여 5개의 멤버를 갖도록 변경합니다.
참고
단방향 확장 만 지원됩니다.
샤드, config 서버 또는 mongos 복제본을 확장하다 때는 확장 의 정확성을 보장하기 위해서만 리소스를 확장하다 하거나 축소할 수 있습니다. 이 규칙은 단일 Kubernetes 클러스터 배포와 여러 Kubernetes 클러스터에 분산된 배포 모두에 적용됩니다. 또한 멀티 클러스터 배포에서는 단방향 확장 규칙이 모든 리소스 유형에 적용됩니다. 예시 들어 샤드에 노드를 더 추가(확장 )하면서 config 서버 또는 mongos 제거( 확장 )할 수 없습니다. 더 이상 총 멤버 수를 변경하지 않고는 한 클러스터 에서 다른 클러스터로 한 노드 '이동'할 수 없습니다. 대신 먼저 확장 작업을 수행한 다음 확장 를 위한 별도의 변경을 실행해야 합니다.
이 예시 구성은 또한 샤드 sc-0에 대해 프라이머리 클러스터 2로 (shardOverrides 사용) 이동시켜 클러스터 2 이 위치한 리전 에서 작업하는 사용자의 지연 시간 줄일 수 있습니다. 이러한 방식으로 클러스터(및 해당 리전) 전체에서 여전히 회복 탄력성 유지할 수 있지만, 샤드 0 의 데이터가 클러스터 2 이 배포된 사용자와 가장 관련성이 높은 데이터인 경우 지연 시간 단축됩니다.
apiVersion: mongodb.com/v1kind: MongoDBmetadata: name: scspec: topology: MultiCluster type: ShardedCluster # this deployment will have 3 shards shardCount: 3 # you cannot specify mongodsPerShardCount, configServerCount and mongosCount # in MultiCluster topology version: 8.0.3 opsManager: configMapRef: name: my-project credentials: my-credentials persistent: true
shardPodSpec: # applies to all shards on all clusters persistence: single: # all pods for all shards on all clusters will use that storage size in their # PersistentVolumeClaim unless overridden in spec.shard.clusterSpecList or # spec.shardOverrides. storage: 10G
configSrvPodSpec: # applies to all config server nodes in all clusters persistence: multiple: data: storage: 2G journal: storage: 1G logs: storage: 1G
# consider this section as a default configuration for ALL shards shard: clusterSpecList: - clusterName: kind-e2e-cluster-1 # each shard will have only one mongod process deployed in this cluster members: 1 memberConfig: - votes: 1 priority: "20" # we increase the priority to have primary in this cluster - clusterName: kind-e2e-cluster-2 # one member in this cluster, no votes and priority defined means it'll get # the default values votes=1, priority="1" members: 1 - clusterName: kind-e2e-cluster-3 members: 1 # one member in this cluster
shardOverrides: # here you specify customizations for specific shards # here you specify to which shard names the following configuration will # apply - shardNames: - sc-0 clusterSpecList: - clusterName: kind-e2e-cluster-1 # all fields here are optional # shard "sc-0" will have two members instead of one, which was defined as the # default for all shards in spec.shard.clusterSpecList[0].members members: 2 memberConfig: - votes: 1 # shard "sc-0" should not have primary in this cluster like every other shard priority: "1" - votes: 1 priority: "1" - clusterName: kind-e2e-cluster-2 members: 2 # shard "sc-0" will have two members instead of one memberConfig: - votes: 1 # both processes of shard "sc-0" in this cluster will have the same # likelihood to become a primary member priority: "20" - votes: 1 priority: "20" # We need to specify the list of all clusters on which this shard will be # deployed. - clusterName: kind-e2e-cluster-3 # If the clusterName element is omitted here, it will be considered as an # override for this shard, so that the operator shouldn't deploy any member # to it. # No fields are mandatory in here, though. In case a field is not set, it's # not overridden and the default value is taken from a top level spec.shard # settings.
configSrv: # the same configuration fields are available as in # spec.shard.clusterSpecList. clusterSpecList: - clusterName: kind-e2e-cluster-1 members: 1 - clusterName: kind-e2e-cluster-2 members: 1 - clusterName: kind-e2e-cluster-3 members: 1
mongos: # the same configuration fields are available as in # spec.shard.clusterSpecList apart from storage and replica-set related # fields. clusterSpecList: - clusterName: kind-e2e-cluster-1 members: 1 - clusterName: kind-e2e-cluster-2 members: 1 - clusterName: kind-e2e-cluster-3 members: 1샤드 재정의
클러스터를 여러 Kubernetes 클러스터에 배포하려면 MongoDB 연산자 인스턴스가 배포된 Kubernetes 클러스터인 중앙 클러스터에 클러스터 구성(MongoDB 사용자 지정 리소스 yaml)을 적용합니다. 이 구성의 spec.shard 정의는 배포의 기본 샤드 정의로 간주됩니다.
특정 Kubernetes 클러스터에서 특정 샤드를 사용자 지정하려면 샤드 재정의를 사용하여 지정된 샤드 에 대한 기본 샤드 정의를 업데이트 수 있습니다.
다음 표에는 기본 샤드 정의를 업데이트 하거나 확장하기 위해 정의할 수 있는 필드가 나열되어 있습니다. 필드는 우선 순위에 따라 나열됩니다. 지정된 테이블의 맨 위에 있는 필드 우선 순위가 가장 낮은 설정을 나타내며, 가장 아래에 있는 필드 정의된 경우 다른 모든 필드를 재정의합니다(예: 특정 샤드, 특정 클러스터).
또한 각 필드 유형에 대해 표시된 재정의 정책은 특정 필드 새로 정의된 값으로 재정의되는지, 또는 해당 필드 정의된 전체 객체 재정의되는지 여부를 설명합니다. 전체 객체 재정의되면 기본 샤드 정의에 정의된 필드 중 재정의 정의에 명시적으로 정의되지 않은 모든 필드가 제거됩니다. merge 값은 단일 필드 업데이트됨을 나타내고 replace 값은 다음을 나타냅니다. 완전한 상위 객체 재정의됩니다.
지속성 및 Statefulset 설정 사용자 지정
ShardedClusterSpec 필드 | 지정하려면 | 적용 대상 |
|---|---|---|
| 지속성 및 파드 템플릿 | 모든 pod |
| 지속성 및 파드 템플릿 | 모든 pod |
| 지속성(Pod Template 필드 무시됨) | 클러스터 의 모든 샤드 |
| Pod Template | 클러스터 의 모든 샤드 |
| 지속성(Pod Template 필드 무시됨) | 클러스터 의 모든 샤드 |
| Pod Template | 클러스터 내 샤드 1개 |
| 지속성(Pod Template 필드 무시됨) | 특정 클러스터 의 샤드 1개 |
| Pod Template | 특정 클러스터 의 샤드 1개 |
참고
ShardSpecificPodSpec 지원 중단
ShardSpecificPodSpec 필드 더 이상 사용되지 않지만 여전히 지원됩니다. 이전에는 단일 클러스터 샤딩된 클러스터 에 대해 샤드당 지속성 및 파드 템플릿 매개변수를 지정하는 데 사용되었습니다. 이제 더 이상 사용되지 않으므로 ShardOverrides.PodSpec 및(으)로 마이그레이션 해야 ShardOverrides.StatefulSetConfiguration 합니다. 단일 클러스터 배포를 위해 shardSpecificPodSpec 및 shardOverrides 에서 업데이트하는 방법에 대한 지침 제공된 예시 YAML 파일 참조하세요.
다음에서 pod 템플릿 및 지속성 설정을 재정의합니다. clusterSpecList
다음 예시 clusterSpecList에서 사용자 지정 파드 템플릿 및 지속성 설정을 재정의하는 방법을 보여줍니다.
shardPodSpec: # applicable to all shards in all clusters persistence: single: storage: "5G" podTemplate: spec: containers: - name: mongodb-enterprise-database resources: requests: cpu: 0.5 memory: 1.0G limits: cpu: 1.0 memory: 2.0G shard: clusterSpecList: - clusterName: kind-e2e-cluster-1 members: 2 # The below statefulset override is applicable only to pods in kind-e2e-cluster-1 # Specs will be merged, the "request" field defined above will still be # applied to containers in this cluster. # However, limits will be replaced with below values, because # clusterSpecList.statefulSet.spec.template has a # higher priority than shardPodSpec.podTemplate statefulSet: spec: template: spec: containers: - name: mongodb-enterprise-database resources: limits: cpu: 1.0 memory: 2.5G # In clusterSpecList.podSpec, only persistence field must be used, the # podTemplate field is ignored. # In kind-e2e-cluster-1, we replace the persistence settings defined in # shardPodSpec podSpec: persistence: multiple: journal: storage: "6G" data: storage: "7G" logs: storage: "6G" - clusterName: kind-e2e-cluster-2 members: 1자세한 학습 은 전체 파일검토 참조하세요.
다음을 사용하여 사용자 지정 파드 템플릿 및 지속성 설정을 정의합니다. shardOverrides
다음 예시 shardOverrides에서 사용자 지정 파드 템플릿 및 지속성 설정을 정의하는 방법을 보여줍니다.
# In clusterSpecList.podSpec, only persistence field must be used, the # podTemplate field is ignored. # In kind-e2e-cluster-1, we define custom persistence settings podSpec: persistence: multiple: journal: storage: "5G" data: storage: "5G" logs: storage: "5G" - clusterName: kind-e2e-cluster-2 members: 1
shardOverrides: - shardNames: [ "pod-template-shards-1-2" ] # This override will apply to shard of index 2 # Statefulset settings defined at this level (shardOverrides.statefulSet) # apply to members of shard 2 in ALL clusters. # This field has higher priority than shard.clusterSpecList.statefulSet, but # lower than shardOverrides.clusterSpecList.statefulSet # It has a merge policy, which means that the limits defined above for the # mongodb-enterprise-database container field still apply to all members in # that shard, except if overridden. statefulSet: spec: template: spec: containers: - name: sidecar-shard-2 image: busybox command: [ "sleep" ] args: [ "infinity" ] clusterSpecList: - clusterName: kind-e2e-cluster-1 members: 2 - clusterName: kind-e2e-cluster-2 members: 1 # The below statefulset override is applicable only to members of shard 2, in cluster 1 # Specs will be merged, the "limits" field defined above will still be applied # to containers in this cluster together with the requests field below. statefulSet: spec: template: spec: containers: - name: mongodb-enterprise-database resources: requests: # We add a requests field in shard 2, cluster 1 cpu: 0.5 memory: 1.0G
podSpec: # In shardOverrides.clusterSpecList.podSpec, only persistence field must be # used, the podTemplate field is ignored. persistence: # we assign additional disk resources in shard 2, cluster 1 multiple: journal: storage: "6G" data: storage: "6G" logs: storage: "6G"자세한 학습 은 전체 파일검토 참조하세요.
더 이상 사용되지 않는 shardSpecificPodSpec 필드에서 마이그레이션
다음 예시 더 이상 사용되지 않는 shardSpecificPodSpec 필드 에서 새 shardOverrides 필드 로 업데이트 방법을 보여 줍니다.
# This file is an example of how to migrate from the old deprecated# ShardSpecificPodSpec field to the new shardOverrides fields# for single cluster deployments.# The settings specified in shardOverrides are the exact equivalent to the# ones in shardSpecificPodSpec, showing how to replicate themapiVersion: mongodb.com/v1kind: MongoDBmetadata: name: shardspecificpodspec-migration namespace: mongodb-testspec: # There are 4 shards in this cluster, but the shardSpecificPodSpec field # doesn't need to have on entry per shard, it can have less shardCount: 4 mongodsPerShardCount: 2 mongosCount: 1 configServerCount: 3 topology: SingleCluster type: ShardedCluster version: 8.0.3 opsManager: configMapRef: name: my-project credentials: my-credentials persistent: true
shardPodSpec: # default persistence configuration for all shards in all clusters persistence: single: storage: "5G" shardSpecificPodSpec: # deprecated way of overriding shards (array) - persistence: # shard of index 0 single: storage: "6G" # Specify resources settings to enterprise database container in shard 0 podTemplate: spec: containers: - name: mongodb-enterprise-database resources: requests: cpu: 0.5 memory: 1G limits: cpu: 1.0 memory: 2.0G - persistence: # shard of index 1 single: storage: "7G" - persistence: # shard of index 2 single: storage: "7G"
# The below shardOverrides replicate the same shards configuration as the one # specified above in shardSpecificPodSpec shardOverrides: - shardNames: [ "shardspecificpodspec-migration-0" ] # overriding shard #0 podSpec: persistence: single: storage: "6G" statefulSet: spec: template: spec: containers: - name: mongodb-enterprise-database resources: requests: cpu: 0.5 memory: 1G limits: cpu: 1.0 memory: 2.0G
# The ShardSpecificPodSpec field above has the same configuration for shards # 1 and 2. It is possible to specify both shard names in the override and not # duplicate that configuration - shardNames: [ "shardspecificpodspec-migration-1", "shardspecificpodspec-migration-2" ] podSpec: persistence: single: storage: "7G"자세한 학습 은 전체 파일검토 참조하세요.
외부 액세스 구성
필드 | 클러스터 | 어떤 샤드 |
|---|---|---|
| 모두 | 모두 |
| one | 모두 |
| one | 모두 |
Members, MemberConfig, 추가 MongodConfig, AgentConfig
ShardedClusterSpec 필드 | 지정하려면 | 적용 대상 |
|---|---|---|
| 해당 사항 없음 | 해당 사항 없음 |
| 적용 | 적용 |
| 적용 | 적용 |
| 해당 사항 없음 | 해당 사항 없음 |
| 적용 | 적용 |
config 서버 재정의
ShardedClusterSpec 필드 | 지정하려면 | 적용 대상 |
|---|---|---|
| 해당 사항 없음 | 해당 사항 없음 |
| 적용 | 적용 |
| 해당 사항 없음 | 해당 사항 없음 |
| 적용 | 무시됨 |
| 해당 사항 없음 | 적용 |
configSrv: clusterSpecList: - clusterName: kind-e2e-cluster-1 members: 2 # The below statefulset override is applicable only to pods in kind-e2e-cluster-1 # Specs will be merged, the "request" field defined above will still be applied to containers in this cluster # However, limits will be replaced with below values, because clusterSpecList.statefulSet.spec.template has a # higher priority than configSrvPodSpec.podTemplate statefulSet: spec: template: spec: containers: - name: mongodb-enterprise-database resources: limits: cpu: 1.0 memory: 2.5G # In clusterSpecList.podSpec, only persistence field must be used, the podTemplate field is ignored. podSpec: # In kind-e2e-cluster-1, we replace the persistence settings defined in configSrvPodSpec persistence: multiple: journal: storage: "6G" data: storage: "7G" logs: storage: "6G" - clusterName: kind-e2e-cluster-2 members: 1 # doc-highlight-end: configSrv mongos: clusterSpecList: - clusterName: kind-e2e-cluster-1 members: 2 - clusterName: kind-e2e-cluster-2 members: 1
shard: clusterSpecList: - clusterName: kind-e2e-cluster-1 members: 2 - clusterName: kind-e2e-cluster-2 members: 1자세한 학습 은 전체 파일검토 참조하세요.
Mongos 재정의
ShardedClusterSpec 필드 | 지정하려면 | 적용 대상 |
|---|---|---|
| 해당 사항 없음 | 해당 사항 없음 |
| 적용 | 해당 사항 없음 |
| 해당 사항 없음 | 적용 |
| 무시됨 | 해당 사항 없음 |
| 적용 | 해당 사항 없음 |