NodeAffinity 및 PodAffinity 를 정의하여 Kubernetes 내에서 MongoDB 리소스의 배포서버 토폴로지 를 구성할 수 있습니다. NodeAffinity 및 PodAffinity 은 Kubernetes Kubernetes 클러스터 MongoDB 사용자 지정 리소스를 배포하는 위치를 지정합니다.
You can implement node affinity by applying node labels to specific nodes within your Kubernetes cluster and defining labelSelector fields with corrosponding labels in your MongoDB CustomResourceDefinition. When you apply node labels and matching labelSelector values, Kubernetes only deploys a given MongoDB CustomResourceDefinition on the nodes you specify within your Kubernetes cluster. Implementing node affinity rules can be useful when deploying MongoDB resources in heterogeneous node groups, as it allows you to deploy specific resources on specific node varieties.
Similarly, you can implement Pod affinity by applying labels to Pods that are running in your cluster and aligning those label values with labelSelector values defined in your MongoDB CustomResourceDefinition. When you apply labels and matching labelSelector values, Kubernetes colocates MongoDB custom resource-managed Pods with Pods with matching labels applied. By collocating Pods, you can improve system performance and reduce latency between Pods that communicate regularly. You can also define Pod antiaffinity rules which allow you to specify Pods which should not be colocated.
For Standalone and Replica Set deployments, you can apply these affinity rules to the spec.podSpec of your MongoDB CustomResourceDefinition. For Sharded Cluster deployments, you can apply these affinity rules to the spec.configSrvPodSpec, spec.shardPodSpec, and spec.mongosPodSpec sections of your MongoDB CustomResourceDefinition.
샤드 클러스터 배포서버 의 경우 mongos, 샤드 및 config 서버와 같은 MongoDB 리소스를 MongoDB 리소스 와 동일한 네임스페이스 에 배포 해야 합니다. 그러나 해당 네임스페이스 내에서는 ShardedCluster CustomResourceDefinition에서 mongos, 샤드 및 config 서버 리소스 유형에 대해 nodeAffinity 및 podAffinity 를 구성할 수 있습니다.
전제 조건
MongoDB deployment 에 대한 배포서버 토폴로지 구성하려면 MongoDB Kubernetes Operator를 통해 배포된 MongoDB 복제본 세트 있어야 하며,labelSelectors MongoDB CustomResourceDefinition에 정의된 에 정의된 Kubernetes 리소스에 적용된 레이블이 있거나 다음 전제 조건을 충족해야 합니다.
MongoDB CustomResourceDefinition 에 정의된 와(과) 일치하는 Kubernetes 리소스에 적용되는
labelSelectors레이블입니다. .
절차
MongoDB CRD 매니페스트를 업데이트합니다.
다음 예시 와 같이 MongoDB 샤드 클러스터 정의의 podTemplate.spec.affinity 섹션을 채웁니다.
1 2 apiVersion: mongodb.com/v1 3 kind: MongoDB 4 metadata: 5 name: my-sharded-cluster 6 spec: 7 shardCount: 2 8 mongodsPerShardCount: 3 9 mongosCount: 2 10 configServerCount: 3 11 version: 8.0.0 12 service: my-service 13 14 opsManager: 15 configMapRef: 16 name: my-project 17 credentials: my-credentials 18 type: ShardedCluster 19 20 persistent: true 21 configSrvPodSpec: 22 podTemplate: 23 spec: 24 affinity: 25 podAffinity: 26 requiredDuringSchedulingIgnoredDuringExecution: 27 - labelSelector: 28 matchExpressions: 29 - key: security 30 operator: In 31 values: 32 - S1 33 topologyKey: failure-domain.beta.kubernetes.io/zone 34 nodeAffinity: 35 requiredDuringSchedulingIgnoredDuringExecution: 36 nodeSelectorTerms: 37 - matchExpressions: 38 - key: kubernetes.io/e2e-az-name 39 operator: In 40 values: 41 - e2e-az1 42 - e2e-az2 43 podAntiAffinity: 44 requiredDuringSchedulingIgnoredDuringExecution: 45 - podAffinityTerm: 46 topologyKey: nodeId 47 mongosPodSpec: 48 podTemplate: 49 spec: 50 affinity: 51 podAffinity: 52 requiredDuringSchedulingIgnoredDuringExecution: 53 - labelSelector: 54 matchExpressions: 55 - key: security 56 operator: In 57 values: 58 - S1 59 topologyKey: failure-domain.beta.kubernetes.io/zone 60 nodeAffinity: 61 requiredDuringSchedulingIgnoredDuringExecution: 62 nodeSelectorTerms: 63 - matchExpressions: 64 - key: kubernetes.io/e2e-az-name 65 operator: In 66 values: 67 - e2e-az1 68 - e2e-az2 69 podAntiAffinity: 70 requiredDuringSchedulingIgnoredDuringExecution: 71 - podAffinityTerm: 72 topologyKey: nodeId 73 shardPodSpec: 74 podTemplate: 75 spec: 76 affinity: 77 podAffinity: 78 requiredDuringSchedulingIgnoredDuringExecution: 79 - labelSelector: 80 matchExpressions: 81 - key: security 82 operator: In 83 values: 84 - S1 85 topologyKey: failure-domain.beta.kubernetes.io/zone 86 nodeAffinity: 87 requiredDuringSchedulingIgnoredDuringExecution: 88 nodeSelectorTerms: 89 - matchExpressions: 90 - key: kubernetes.io/e2e-az-name 91 operator: In 92 values: 93 - e2e-az1 94 - e2e-az2 95 podAntiAffinity: 96 requiredDuringSchedulingIgnoredDuringExecution: 97 - podAffinityTerm: 98 topologyKey: nodeId 99 ...