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

MongoDB 插件参考

使用kubectl mongodb插件可以:

开始之前,请安装 kubectl mongodb 插件。

kubectl mongodb插件具有以下子命令:

kubectl mongodb multicluster setup子命令设置初始多 Kubernetes 集群 MongoDB 部署。 它执行以下操作:

  • 创建一个名为mongodb-kubernetes-operator-member-list的默认ConfigMap,其中包含多 Kubernetes集群MongoDB 部署的所有成员集群。 此名称是硬编码的,无法更改。 请参阅已知问题。

  • 在操作符集群和每个成员集群中创建 ServiceAccountsRoles、ClusterRolesRoleBindings 和 ClusterRoleBindings

  • 为服务帐户应用正确的权限。

  • 使用前面的设置创建多 Kubernetes 集群 MongoDB 部署。

kubectl mongodb插件的setup子命令具有以下选项:

选项
数据类型
说明

central-cluster

字符串

必需。 将部署 Kubernetes 操作符的中央集群,例如: --central-cluster="MDB_CENTRAL_CLUSTER_FULL_NAME"

central-cluster-namespace

字符串

必需。 Kubernetes 操作符将部署到的命名空间,例如: --central-cluster-namespace="mongodb"

cleanup

布尔

可选。 指示是否删除以前创建的除命名空间之外的所有资源的标志。 默认值为false

cluster-scoped

布尔

可选。 指示是否为成员集群创建 ClusterRole 和 ClusterRoleBindings 的标志。 默认值为false

create-service-account-secrets

布尔

Optional. Flag that indicates whether to create secrets for the service accounts in the Kubernetes API server. Default value is false.

install-database-roles

布尔

可选。 指示是否安装在成员集群上运行 MongoDB 工作负载所需的服务帐户和角色的标志。 默认值为false

image-pull-secrets

布尔

可选。 标志,表示kubectl mongodb插件创建的服务帐户是否应引用您在注册表中指定的密钥。imagePullSecrets 设置。 默认值为false 。 要学习;了解更多信息,请参阅Helm 安装设置。

member-clusters

字符串

必需。 以逗号分隔的列表,包含成员集群,例如: -member-clusters="${MDB_CLUSTER_2_FULL_NAME}, ${MDB_CLUSTER_3_FULL_NAME}, ${MDB_CLUSTER_4_FULL_NAME}"

member-cluster-ca

字符串

Optional. Path to a PEM-encoded CA bundle that the Kubernetes Operator uses to reach a member cluster's Kubernetes API server, in the format --member-cluster-ca <member-cluster-name>=<path-to-pem-file>. Repeat the option once for each member cluster that requires its own CA bundle. If you omit a member cluster, the kubectl mongodb plugin uses the CA from that cluster's service account token secret. To learn more, see Custom CA Bundles for Member Clusters.

member-cluster-namespace

字符串

必需。 成员集群资源将部署到的命名空间,例如: -member-cluster-namespace="mongodb"

service-account

字符串

可选。 Kubernetes 操作符用于与成员集群通信的服务帐户名称。默认值为mongodb-kubernetes-operator-multi-cluster

有关kubectl mongodb插件setup子命令用法的完整示例,请参阅多Kubernetes集群快速入门。

在某些情况下, kubectl mongodb multicluster子命令可以自动恢复出现故障的集群拓扑。 在其他情况下,您必须手动从故障中恢复。 要了解更多信息,请参阅灾难恢复。

kubectl mongodb插件的recover子命令具有以下选项:

选项
数据类型
说明

central-cluster

字符串

必需。 将部署 Kubernetes 操作符的中央集群,例如: --central-cluster="MDB_CENTRAL_CLUSTER_FULL_NAME"

central-cluster-namespace

字符串

必需。 Kubernetes 操作符将部署到的命名空间,例如: --central-cluster-namespace="mongodb"

cleanup

布尔

可选。 指示是否删除以前创建的除命名空间之外的所有资源的标志。 默认值为false

cluster-scoped

布尔

可选。 指示是否为成员集群创建 ClusterRole 和 ClusterRoleBindings 的标志。 默认值为false

member-cluster-ca

字符串

Optional. Path to a PEM-encoded CA bundle that the Kubernetes Operator uses to reach a member cluster's Kubernetes API server, in the format --member-cluster-ca <member-cluster-name>=<path-to-pem-file>. Repeat the option once for each member cluster that requires its own CA bundle. If you omit a member cluster, the kubectl mongodb plugin uses the CA from that cluster's service account token secret. To learn more, see Custom CA Bundles for Member Clusters.

有关kubectl mongodb插件recover子命令用法的完整示例,请参阅手动灾难恢复过程。

By default, the kubectl mongodb plugin reads the CA for each member cluster from that cluster's service account token secret and writes it to the generated mongodb-enterprise-operator-multi-cluster-kubeconfig secret. In some cases, you might want to supply a custom CA bundle, for example: when the network path from the Kubernetes Operator to a member cluster's Kubernetes API server terminates TLS elsewhere, such as at a proxy or load balancer that presents its own certificate. Use the member-cluster-ca option to supply a custom CA bundle.

以下命令为三个成员集群中的两个提供 CA 捆绑包:

kubectl mongodb multicluster setup \
--central-cluster="operator-cluster" \
--member-clusters="cluster-1,cluster-2,cluster-3" \
--member-cluster-namespace=mongodb \
--central-cluster-namespace=mongodb \
--member-cluster-ca cluster-1=/path/to/cluster-1-ca.pem \
--member-cluster-ca cluster-2=/path/to/cluster-2-ca.pem

In the preceding example, cluster-3 keeps the CA from its service account token secret.

The kubectl mongodb plugin copies the file contents into the KubeConfig secret without modification, so pass certificates only. Each file must meet the following requirements:

  • 包含至少一个 PEM 编码的证书。

  • Contains no private key. A bundle that a TLS terminator exports might place the server key next to its certificate. The plugin rejects such a bundle with the error found a private key (<block type> block), pass certificates only.

The plugin also returns an error if you pass a malformed <member-cluster-name>=<path-to-pem-file> pair, name a member cluster that member-clusters doesn't list, or name the same member cluster more than once.

Both the setup and recover subcommands regenerate the entire KubeConfig secret. If you omit a member cluster from member-cluster-ca on a later run, that cluster reverts to the CA from its service account token secret. To preserve a custom CA, every time you run either subcommand make sure to re-pass the member-cluster-ca option for every member cluster that requires one.

当子命令替换与成员集群的服务帐户令牌密钥不匹配的 CA 时,该插件会打印类似于以下内容的警告:

Warning: replacing the CA for member cluster cluster-1, which does not match its ServiceAccount token secret. Pass --member-cluster-ca cluster-1=<path-to-pem-file> to keep a custom CA.

该警告为建议性警告。该子命令仍会完成并写入新的 KubeConfig 密钥。