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环境。
Considerations
每个项目只能部署一个 MongoDB 资源。 应用此限制是因为 Ops Manager 仅支持针对每个项目的数据库用户访问的一种身份验证方法。 要了解更多信息,请参阅部署 MongoDB database 资源。
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.projectNamefrom 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控制器
使用 ConfigMap 创建一个项目
将kubectl 配置为默认命名空间。
如果您尚未执行,请运行以下命令,执行所创建命名空间的所有 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>
调用以下命令来创建 ConfigMap。
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
键 | 类型 | 说明 | 例子 |
|---|---|---|---|
| 字符串 |
| |
| 字符串 |
| |
| 字符串 | 您的 Ops Manager 项目的标签。 The Kubernetes Operator creates the Ops Manager project if it does not exist. If you omit the 如需使用 Cloud Manager 或 Ops Manager 组织中的现有项目,请单击 Cloud Manager 或 Ops Manager 页面左上方的 All Clusters 链接找到 |
|
| 字符串 | 必需。 24 字符的十六进制string ,用于唯一标识您的Cloud Manager或MongoDB Ops Manager组织。 您可以使用 Kubernetes Operator 通过 Cloud Manager 和 Ops Manager 6.0.x 版或更高版本来部署 MongoDB 资源。 可以使用 Atlas Operator 将 MongoDB 资源部署到 Atlas。 指定现有组织:
必须具备组织项目创建者角色才能在现有 Cloud Manager 或 Ops Manager 组织中创建新项目。 如果您提供空字符串作为 |
|
| 字符串 | Ops Manager 应用程序的 URL,包括 FQDN 和端口号。 重要提示: 如果您使用MongoDB Ops Manager KubernetesOperator部署MongoDB Ops Manager MongoDBKubernetes,并且 将管理部署在其所部署到的 集群 外部 的 数据库资源,则必须设立 如果使用 Cloud Manager,请将 |
|
调用以下Kubernetes命令来验证您的ConfigMap。
kubectl describe configmaps <configmap-name>
此命令在 shell 中返回 ConfigMap 描述:
Name: <configmap-name> Namespace: <namespace> Labels: <none> Annotations: <none> Data ==== baseUrl: ---- <myOpsManagerURL> Events: <none>
使用自定义 CA 连接到启用 HTTPS 的 Ops Manager
您可能已选择使用自己的TLS证书为 Ops Manager 实例启用HTTPS 。 如果您使用自定义证书,则需要将签署该自定义证书的 CA 添加到 Kubernetes Operator。 要添加自定义 CA,请完成以下操作:
为证书颁发机构 (CA) 证书创建 ConfigMap。
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 。
复制以下示例ConfigMap 的突出显示部分。
1 2 apiVersion: v1 3 kind: ConfigMap 4 metadata: 5 name: <my-configmap> 6 namespace: <my-namespace> 7 data: 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 ...
将突出显示的部分添加到项目的 ConfigMap 中。
调用以下命令,在默认配置编辑器中编辑项目的 ConfigMap:
kubectl edit configmaps <my-configmap> -n <metadata.namespace> 粘贴示例 ConfigMap 中突出显示的部分 在项目 ConfigMap 结束时。
指定 TLS 设置
更改以下TLS密钥:
键 | 类型 | 说明 | 例子 |
|---|---|---|---|
| 字符串 | ConfigMap 的名称 在第一步中创建的证书,其中包含用于签署 主机证书的根 CA MongoDB Ops Manager证书。这会将 CA 证书挂载到 Kubernetes Operator 和数据库资源。 |
|
| 布尔 | 强制 Operator 要求 提供有效的 TLS MongoDB Ops Manager证书。 重要提示:该值必须用单引号括起来,否则操作符将引发错误。 |
|
调用Kubernetes命令来验证您的 ConfigMap 。
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 创建档案 。