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

使用 ConfigMap 为每个MongoDB部署创建一个项目

The MongoDB Controllers for Kubernetes Operator uses a Kubernetes ConfigMap to link to a single and unique Ops Manager Project. If the referenced project doesn't exist, the Kubernetes Operator creates it according to the projectName that you provide in the ConfigMap.

要创建 Kubernetes Operator ConfigMap,您可以编辑示例 ConfigMap YAML 文件的几行并应用 ConfigMap。要查看完整示例,请参阅项目.yaml文件。

或者,您可以使用MongoDB Cloud Manager用户界面或MongoDB Ops Manager用户界面创建或选择项目,并自动生成 ConfigMap YAML文件,然后将其应用到Kubernetes环境。

  1. 每个项目只能部署一个 MongoDB 资源。 应用此限制是因为 Ops Manager 仅支持针对每个项目的数据库用户访问的一种身份验证方法。 要了解更多信息,请参阅部署 MongoDB database 资源。

  2. You must pair a MongoDB Controllers for Kubernetes Operator deployment to a unique Ops Manager Project. You can either create a distinct ConfigMap for each MongoDB Controllers for Kubernetes Operator instance you deploy, or you can reuse the same ConfigMap for any number of deployments by omitting the data.projectName from your ConfigMap, so that project names align with deployed resource names. Where a project name is provided in the config map, if that project does not exist yet it will be created.

重要

  • 您可以使用 Kubernetes Operator 通过 Cloud Manager 和 Ops Manager 6.0.x 版或更高版本来部署 MongoDB 资源。

  • 可以使用 Atlas Operator 将 MongoDB 资源部署到 Atlas。

  • Kubernetes 版本 1.11 或更高版本或者 Openshift 版本 3.11 或更高版本。

  • 适用于Kubernetes Operator 的MongoDB控制器

    已安装。

1

如果您尚未执行,请运行以下命令,执行所创建命名空间的所有 kubectl 命令。

注意

MongoDB Ops Manager如果要在多 Kubernetes 集群 部署中部署MongoDB 资源:

  • context 设置为操作符集群的名称,例如:kubectl config set context "$MDB_CENTRAL_CLUSTER_FULL_NAME"

  • --namespace设置为您用于多 Kubernetes 集群 MongoDB 部署的相同范围,例如: kubectl config --namespace "mongodb"

kubectl config set-context $(kubectl config current-context) --namespace=<metadata.namespace>
2
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: my-project
namespace: mongodb
data:
projectName: myProjectName # this is an optional parameter; when omitted, the Operator creates a project with the resource name
orgId: 5b890e0feacf0b76ff3e7183 # this is a required parameter
baseUrl: https://ops.example.com:8443
EOF
类型
说明
例子

metadata.name

字符串

Kubernetes 对象的名称。

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

This name must follow RFC1123 naming conventions, containing only lowercase alphanumeric characters or - , and starting and ending with an alphanumeric character.

To learn more, see Kubernetes documentation on names.

my-project

metadata.namespace

字符串

Kubernetes namespace where the Kubernetes Operator creates this MongoDB resource and other objects.

mongodb

data.projectName

字符串

您的 Ops Manager 项目的标签。

The Kubernetes Operator creates the Ops Manager project if it does not exist. If you omit the projectName, the Kubernetes Operator creates a project with the same name as your Kubernetes resource.

如需使用 Cloud Manager 或 Ops Manager 组织中的现有项目,请单击 Cloud Manager 或 Ops Manager 页面左上方的 All Clusters 链接找到 projectName,然后在 Search 框中按名称搜索,或滚动到列表中查找名称。此列表中的每张卡片都代表单个“Cloud Manager 或 Ops Manager 组织项目”的组合。

myProjectName

data.orgId

字符串

必需。 24 字符的十六进制string ,用于唯一标识您的Cloud Manager或MongoDB Ops Manager组织。

您可以使用 Kubernetes Operator 通过 Cloud Manager 和 Ops Manager 6.0.x 版或更高版本来部署 MongoDB 资源。

可以使用 Atlas Operator 将 MongoDB 资源部署到 Atlas。

指定现有组织:

  1. 查找该组织的 ID。

    点击左侧导航栏中的 Settings

  2. 将 orgId 复制并粘贴到 URL 中。

    Select your organization, view the current URL in your browser and copy the value displayed in the <orgId> placeholder as follows:

    https://ops.example.com:8443/ v2#/org/<orgId>/projects

必须具备组织项目创建者角色才能在现有 Cloud Manager 或 Ops Manager 组织中创建新项目。

如果您提供空字符串作为 orgId,Kubernetes Operator 会创建一个与您的项目同名的组织。

5b890e0feacf0b76ff3e7183

data.baseUrl

字符串

Ops Manager 应用程序的 URL,包括 FQDN 和端口号。

重要提示: 如果您使用MongoDB Ops Manager KubernetesOperator部署MongoDB Ops Manager MongoDBKubernetes,并且 将管理部署在其所部署到的 集群 外部 的 数据库资源,则必须设立data.baseUrl 设置为与spec.configuration.mms.centralUrl 中的MongoDB Ops Manager 设置相同的值 资源规范。要学习;了解更多信息,请参阅管理外部MongoDB部署。

如果使用 Cloud Manager,请将 data.baseUrl 值设置为 https://cloud.mongodb.com

https://ops.example.com:8443

3
kubectl describe configmaps <configmap-name>

此命令在 shell 中返回 ConfigMap 描述:

Name: <configmap-name>
Namespace: <namespace>
Labels: <none>
Annotations: <none>
Data
====
baseUrl:
----
<myOpsManagerURL>
Events: <none>

您可能已选择使用自己的TLS证书为 Ops Manager 实例启用HTTPS 。 如果您使用自定义证书,则需要将签署该自定义证书的 CA 添加到 Kubernetes Operator。 要添加自定义 CA,请完成以下操作:

1

The Kubernetes Operator requires the root CA certificate of the CA that issued the Ops Manager host's certificate. Run the following command to create a ConfigMap containing the root CA in the same namespace of your database Pods:

kubectl -n <metadata.namespace> create configmap <root-ca-configmap-name> \
--from-file=mms-ca.crt

重要

Kubernetes 操作符要求您在 ConfigMap 中命名 Ops Manager 资源的证书mms-ca.crt

2
1---
2apiVersion: v1
3kind: ConfigMap
4metadata:
5 name: <my-configmap>
6 namespace: <my-namespace>
7data:
8 projectName: <my-ops-manager-project-name> # this is an optional parameter
9 orgId: <org-id> # this is a required parameter
10 baseUrl: https://<my-ops-manager-URL>
11 sslMMSCAConfigMap: <root-ca-configmap-name>
12 sslRequireValidMMSServerCertificates: ‘true’
13...
3
  1. 调用以下命令,在默认配置编辑器中编辑项目的 ConfigMap:

    kubectl edit configmaps <my-configmap> -n <metadata.namespace>
  2. 粘贴示例 ConfigMap 中突出显示的部分 在项目 ConfigMap 结束时。

4

更改以下TLS密钥:

类型
说明
例子

sslMMSCAConfigMap

字符串

ConfigMap 的名称 在第一步中创建的证书,其中包含用于签署 主机证书的根 CA MongoDB Ops Manager证书。这会将 CA 证书挂载到 Kubernetes Operator 和数据库资源。

my-root-ca

sslRequireValidMMSServerCertificates

布尔

强制 Operator 要求 提供有效的 TLS MongoDB Ops Manager证书。

重要提示:该值必须用单引号括起来,否则操作符将引发错误。

'true'

5
6
kubectl describe configmaps <my-configmap> -n <metadata.namespace>

重要

Always include the namespace option with kubectl. kubectl defaults to an empty namespace if you don't specify the -n option, resulting in deployment failures. You must specify the value of the <metadata.namespace> field. The Kubernetes Operator, secret, and MongoDB resources should run in the same unique namespace.

此命令在 shell 中返回 ConfigMap 描述:

Name: <my-configmap>
Namespace: <namespace>
Labels: <none>
Annotations: <none>
Data
====
sslMMSCAConfigMap:
----
<root-ca-configmap-name>
sslRequireValidMMSServerCertificates:
----
true
Events: <none>

现在您已经创建了 ConfigMap,在开始 部署 MongoDB 资源 之前,请 为 Kubernetes Operator 创建档案 。