Docs 菜单
Docs 主页
/
MongoDB Enterprise Kubernetes Operator
/

为 MongoDB 资源配置集群拓扑

在此页面上

  • 先决条件
  • 步骤

您可以通过定义 NodeAffinityPodAffinity在 Kubernetes 中配置 MongoDB 资源的部署拓扑。 NodeAffinityPodAffinity指定 Kubernetes 在 Kubernetes 集群中部署 MongoDB 自定义资源的位置。

您可以实施 节点关联性 通过应用 节点标签 Kubernetes 集群中的特定节点,并在labelSelector MongoDB CustomResourceDefinition 中使用相应标签定义 字段 。应用 节点标签 时 和匹配的labelSelector 值,Kubernetes 仅部署给定的 MongoDB CustomResourceDefinition 在 Kubernetes 集群中指定的节点上。在异构节点组中部署 MongoDB 资源时,实施节点关联性规则非常有用,因为它允许您在特定的节点类型上部署特定的资源。

同样,您可以通过应用 标签 来实现 Pod 亲和性 到集群中运行的 Pod,并将这些标签值与labelSelector MongoDB CustomResourceDefinition 中定义的 值保持一致labelSelector 。应用 标签 时 和匹配的 值,Kubernetes 将 MongoDB 自定义资源托管 Pod 与应用了匹配标签的 Pod 并置。通过并置 Pod,可以提高系统性能并减少定期通信的 Pod 之间的延迟。您还可以定义 Pod 反关联规则,指定不应共置的 Pod。

对于独立运行和副本集部署,您可以将这些关联性规则应用于spec.podSpec MongoDB CustomResourceDefinition 的 。对于分片集群部署,您可以将这些关联性规则应用于 MongoDBspec.configSrvPodSpec CustomResourceDefinitionspec.mongosPodSpec 的 、spec.shardPodSpec 和 部分 。

您必须将 MonogDB 资源(例如分片集群部署中的mongos 、分片和配置服务器)部署在与 MongoDB 资源相同的命名空间中。但是,在该命名空间内,您可以在nodeAffinity podAffinitymongosShardedClusterCustomResourceDefinition 中为 、分片和配置服务器资源类型配置 和 。 。

要为 MongoDB 部署配置部署拓扑,您必须通过 MongoDB Kubernetes Operator 部署 MongoDB 副本集,并应用应用于 Kubernetes 资源的标签,这些标签将与labelSelectors MongoDB CustomResourceDefinition 中定义的 保持一致 或满足以下先决条件:

1

填充 MongoDB 分片集群定义的podTemplate.affinity部分,如以下示例所示:

1---
2apiVersion: mongodb.com/v1
3kind: MongoDB
4metadata:
5 name: my-sharded-cluster
6spec:
7 shardCount: 2
8 mongodsPerShardCount: 3
9 mongosCount: 2
10 configServerCount: 3
11 version: 6.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...
2
kubectl apply -f mongodb-crd.yaml

后退

配置 MongoDB 数据库备份

来年

为 MongoDB 资源配置存储选项

在此页面上