对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

在多 Kubernetes 集群中部署副本集

使用此过程可在多 Kubernetes 集群 MongoDB 部署中的成员 Kubernetes 集群中创建新副本集。

此过程允许您为副本集设立资源不同的设置,例如覆盖 statefulSet 配置。 作为使用此过程的替代方法,您可以使用多 Kubernetes 集群快速入门,它使用默认设置创建多 Kubernetes集群MongoDB 部署。

开始之前:

您可以在此TLS-Encrypted Connections标签页中执行以下操作步骤:

  • 部署MongoDBMultiCluster资源

  • MongoDBMultiCluster资源续订 TLS 证书

这些过程在副本集的MongoDB主机之间以及客户端应用程序与MongoDB部署之间建立TLS加密连接。

在开始之前,您必须拥有有效的TLS加密证书。

1

运行kubectl命令以创建用于存储MongoDBMultiCluster资源证书的新密钥:

kubectl --context $MDB_CENTRAL_CLUSTER_FULL_NAME \
--namespace=<metadata.namespace> \
create secret tls <prefix>-<metadata.name>-cert \
--cert=<resource-tls-cert> \
--key=<resource-tls-key>

注意

您必须在密钥前面加上 <prefix>-<metadata.name> 作为前缀。

For example, if you call your deployment my-deployment and you set the prefix to mdb, you must name the TLS secret for the client TLS communications mdb-my-deployment-cert. Also, you must name the TLS secret for internal cluster authentication (if enabled) mdb-my-deployment-clusterfile.

2

Run the kubectl command to link your CA to your MongoDBMultiCluster resource. Specify the CA certificate file that you must always name ca-pem for the MongoDBMultiCluster resource:

kubectl --context $MDB_CENTRAL_CLUSTER_FULL_NAME \
--namespace=<metadata.namespace> \
create configmap custom-ca -from-file=ca-pem=<your-custom-ca-file>
3

如果尚未执行此操作,运行以下命令,以便在默认命名空间中的操作符集群上运行所有 kubectl 命令。

kubectl config use-context $MDB_CENTRAL_CLUSTER_FULL_NAME
kubectl config set-context $(kubectl config current-context) \
--namespace=mongodb
4
  1. 复制示例副本集YAML文件并将其粘贴到新的文本文件中。

  2. 更改文件的设置以匹配所需的副本集配置。

1# This example provides statefulSet overrides per cluster.
2
3apiVersion: mongodb.com/v1
4kind: MongoDBMultiCluster
5metadata:
6 name: multi-replica-set
7spec:
8 version: 8.0.0
9 type: ReplicaSet
10 duplicateServiceObjects: false
11 credentials: my-credentials
12 opsManager:
13 configMapRef:
14 name: my-project
15 clusterSpecList:
16 - clusterName: cluster1.example.com
17 members: 2
18 statefulSet:
19 spec:
20 template:
21 spec:
22 containers:
23 # Example of custom sidecar containers. Remove it before using the file in production.
24 - name: sidecar1
25 image: busybox
26 command: [ "sleep" ]
27 args: [ "infinity" ]
28 # Use the following settings to override the default storage size of the "data" Persistent Volume.
29 volumeClaimTemplates:
30 - metadata:
31 name: data
32 spec:
33 resources:
34 requests:
35 storage: 1Gi
36 - clusterName: cluster2.example.com
37 members: 1
38 statefulSet:
39 spec:
40 template:
41 spec:
42 containers:
43 # Example of custom sidecar containers. Remove it before using the file in production.
44 - name: sidecar2
45 image: busybox
46 command: [ "sleep" ]
47 args: [ "infinity" ]
48 volumeClaimTemplates:
49 - metadata:
50 name: data
51 spec:
52 resources:
53 requests:
54 storage: 1Gi
55 - clusterName: cluster3.example.com
56 members: 1
57 statefulSet:
58 spec:
59 template:
60 spec:
61 containers:
62 # Example of custom sidecar containers. Remove it before using the file in production.
63 - name: sidecar3
64 image: busybox
65 command: [ "sleep" ]
66 args: [ "infinity" ]
67 volumeClaimTemplates:
68 - metadata:
69 name: data
70 spec:
71 resources:
72 requests:
73 storage: 1Gi
74
75...
5
类型
说明
例子

字符串

MongoDBMultiCluster资源的标签。

资源名称必须少于或等于 44 个字符。

另请参阅metadata.name 名称 在Kubernetes文档中。

multi-replica-set

字符串

MongoDBMultiCluster资源应运行的 MongoDB 版本。

Community 版的格式应为 X.Y.Z,Enterprise 版的格式应为 X.Y.Z-ent

重要提示:确保选择兼容的MongoDB Server版本。 兼容版本因MongoDB 数据库资源使用的基础映像而异。

要了解有关 MongoDB 版本控制的更多信息,请参阅 MongoDB 手册中的 MongoDB 版本控制

8.0.0

spec
.opsManager
.configMapRef
.name

字符串

Name of the ConfigMap with the Ops Manager connection configuration. The spec.cloudManager.configMapRef.name setting is an alias for this setting and can be used in its place.

此值必须与待创建的资源位于同一命名空间。

重要提示:Kubernetes Operator 会跟踪该 ConfigMap 的任何更改并协调 MongoDB 资源的状态。

<my-project>

spec
.clusterSpecList
.clusterName

字符串

MongoDBMultiCluster资源中集群的名称。

cluster1.example.com

spec
.clusterSpecList
.members

整型

此集群中的成员数。

2

spec
.clusterSpecList
.statefulSet
.spec

集合

可选。

为多 Kubernetes集群MongoDB 部署中集群的每个 StatefulSet 提供 StatefulSet 覆盖的配置。如果在clusterSpecList 下的单个集群级别指定,则覆盖整个多 Kubernetes集群MongoDB 部署的StatefulSet 的全局配置。请参阅多 Kubernetes 集群资源规范和 StatefulSet v1 apps Kubernetes文档。

请参阅示例。

spec
.clusterSpecList
.statefulSet
.spec
.volumeClaimTemplates
.spec

集合

可选。 如果已指定,则为每个集群覆盖 卷 声明模板 的默认存储大小 ,用于存储数据的持久卷。

请参阅示例。

字符串

创建的 Secret 名称,其将作为 Ops Manager API 身份验证凭证,以便 Kubernetes Operator 与 Ops Manager 进行通信。

持有凭证的 Ops Manager Kubernetes Secret 对象必须与您要创建的资源位于同一个命名空间中。

重要提示:Kubernetes Operator 会跟踪该 Secret 的任何更改并协调 MongoDB 资源的状态。

<mycredentials>

字符串

要创建的MongoDB资源的类型。 此字段唯一支持的值为ReplicaSet 。 请参阅限制。

ReplicaSet

6

您还可以为 对象 添加任何可选设置 规范。请参阅多 Kubernetes 集群资源规范。

7
8

在任何目录下,调用以下 Kubernetes 命令以创建副本集

kubectl apply -f <replica-set-conf>.yaml
9

要检查 MongoDBMultiCluster资源的状态,请在操作符集群上使用以下命令:

kubectl get mdbmc <resource-name> -o yaml -w

设置 -w (观看) 标志后,当配置更改时,输出将立即刷新,直到状态阶段达到 Running 状态。要了解有关资源部署状态的详情,请参阅 Kubernetes Operator 故障排除

使用以下过程定期续订TLS证书。

1

Run this kubectl command to renew an existing secret that stores the certificates for the MongoDBMultiCluster resource:

kubectl --context $MDB_CENTRAL_CLUSTER_FULL_NAME \
--namespace=<metadata.namespace> \
create secret tls <prefix>-<metadata.name>-cert \
--cert=<resource-tls-cert> \
--key=<resource-tls-key> \
--dry-run=client \
-o yaml |
kubectl apply -f -

此过程不会加密副本集MongoDB主机之间的连接,以及客户端应用程序与MongoDB部署之间的连接。

1

如果尚未执行此操作,运行以下命令,以便在默认命名空间中的操作符集群上运行所有 kubectl 命令。

kubectl config use-context $MDB_CENTRAL_CLUSTER_FULL_NAME
kubectl config set-context $(kubectl config current-context) \
--namespace=mongodb
2
  1. 复制示例副本集YAML文件并将其粘贴到新的文本文件中。

  2. 更改文件的设置以匹配所需的副本集配置。

1# This example provides statefulSet overrides per cluster.
2
3apiVersion: mongodb.com/v1
4kind: MongoDBMultiCluster
5metadata:
6 name: multi-replica-set
7spec:
8 version: 8.0.0
9 type: ReplicaSet
10 duplicateServiceObjects: false
11 credentials: my-credentials
12 opsManager:
13 configMapRef:
14 name: my-project
15 clusterSpecList:
16 - clusterName: cluster1.example.com
17 members: 2
18 statefulSet:
19 spec:
20 template:
21 spec:
22 containers:
23 # Example of custom sidecar containers. Remove it before using the file in production.
24 - name: sidecar1
25 image: busybox
26 command: [ "sleep" ]
27 args: [ "infinity" ]
28 # Use the following settings to override the default storage size of the "data" Persistent Volume.
29 volumeClaimTemplates:
30 - metadata:
31 name: data
32 spec:
33 resources:
34 requests:
35 storage: 1Gi
36 - clusterName: cluster2.example.com
37 members: 1
38 statefulSet:
39 spec:
40 template:
41 spec:
42 containers:
43 # Example of custom sidecar containers. Remove it before using the file in production.
44 - name: sidecar2
45 image: busybox
46 command: [ "sleep" ]
47 args: [ "infinity" ]
48 volumeClaimTemplates:
49 - metadata:
50 name: data
51 spec:
52 resources:
53 requests:
54 storage: 1Gi
55 - clusterName: cluster3.example.com
56 members: 1
57 statefulSet:
58 spec:
59 template:
60 spec:
61 containers:
62 # Example of custom sidecar containers. Remove it before using the file in production.
63 - name: sidecar3
64 image: busybox
65 command: [ "sleep" ]
66 args: [ "infinity" ]
67 volumeClaimTemplates:
68 - metadata:
69 name: data
70 spec:
71 resources:
72 requests:
73 storage: 1Gi
74
75...
3
类型
说明
例子

字符串

MongoDBMultiCluster资源的标签。

资源名称必须少于或等于 44 个字符。

另请参阅metadata.name 名称 在Kubernetes文档中。

multi-replica-set

字符串

MongoDBMultiCluster资源应运行的 MongoDB 版本。

Community 版的格式应为 X.Y.Z,Enterprise 版的格式应为 X.Y.Z-ent

重要提示:确保选择兼容的MongoDB Server版本。 兼容版本因MongoDB 数据库资源使用的基础映像而异。

要了解有关 MongoDB 版本控制的更多信息,请参阅 MongoDB 手册中的 MongoDB 版本控制

8.0.0

spec
.opsManager
.configMapRef
.name

字符串

Name of the ConfigMap with the Ops Manager connection configuration. The spec.cloudManager.configMapRef.name setting is an alias for this setting and can be used in its place.

此值必须与待创建的资源位于同一命名空间。

重要提示:Kubernetes Operator 会跟踪该 ConfigMap 的任何更改并协调 MongoDB 资源的状态。

<my-project>

spec
.clusterSpecList
.clusterName

字符串

MongoDBMultiCluster资源中集群的名称。

cluster1.example.com

spec
.clusterSpecList
.members

整型

此集群中的成员数。

2

spec
.clusterSpecList
.statefulSet
.spec

集合

可选。

Provides the configuration for the StatefulSet override for each of the cluster's StatefulSets in a multi-Kubernetes cluster MongoDB deployment. If specified at an individual cluster level under clusterSpecList, overrides the global configuration for the StatefulSet for the entire multi-Kubernetes cluster MongoDB deployment. See Multi-Kubernetes-Cluster Resource Specification and StatefulSet v1 apps Kubernetes documentation.

请参阅示例。

spec
.clusterSpecList
.statefulSet
.spec
.volumeClaimTemplates
.spec

集合

可选。 如果已指定,则为每个集群覆盖 卷 声明模板 的默认存储大小 ,用于存储数据的持久卷。

请参阅示例。

字符串

创建的 Secret 名称,其将作为 Ops Manager API 身份验证凭证,以便 Kubernetes Operator 与 Ops Manager 进行通信。

持有凭证的 Ops Manager Kubernetes Secret 对象必须与您要创建的资源位于同一个命名空间中。

重要提示:Kubernetes Operator 会跟踪该 Secret 的任何更改并协调 MongoDB 资源的状态。

<mycredentials>

字符串

要创建的MongoDB资源的类型。 此字段唯一支持的值为ReplicaSet 。 请参阅限制。

ReplicaSet

4

您还可以为 对象 添加任何可选设置 规范。请参阅多 Kubernetes 集群资源规范。

5
6

在任何目录下,调用以下 Kubernetes 命令以创建副本集

kubectl apply -f <replica-set-conf>.yaml
7

要检查 MongoDBMultiCluster资源的状态,请在操作符集群上使用以下命令:

kubectl get mdbmc <resource-name> -o yaml -w

设置 -w (观看) 标志后,当配置更改时,输出将立即刷新,直到状态阶段达到 Running 状态。要了解有关资源部署状态的详情,请参阅 Kubernetes Operator 故障排除

给本页内容打分