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

为Kubernetes Operator 安装MongoDB控制器

在安装 Kubernetes 操作符之前,请确保规划好安装:

注意

本教程假定您具备一定的 Kubernetes 知识,并提供相关 Kubernetes 文档的链接。 如果您不熟悉 Kubernetes,请先查看该文档。

安装过程因您想要配置环境的方式而异:

注意

自始至终使用相同的命名空间

By default, the Kubernetes Operator deploys all resources in your Kubernetes cluster to the namespace mongodb. You can deploy Kubernetes Operator resources to a different namespace by editing all values for metadata.namespace in mongodb-kubernetes.yaml. You must also update the subjects[0].namespace value in every RoleBinding and ClusterRoleBinding in the same file. If you omit this value, the bindings look for the ServiceAccount in the default mongodb namespace and can't find it:

---
apiVersion: v1
kind: ServiceAccount
metadata:
name: mongodb-kubernetes-operator
namespace: production
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: mongodb-kubernetes-operator
namespace: production
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: mongodb-kubernetes-operator
subjects:
- kind: ServiceAccount
name: mongodb-kubernetes-operator
namespace: production
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-kubernetes-operator
namespace: production
---
# Example truncated
---
...
1

要了解可选的 Kubernetes Operator 安装设置,请参阅Operator kubectl 和 oc 安装设置。

注意

要启用静态容器的公共预览版以提高和简化安全性,请参阅静态容器(公共预览版)。当此功能处于公共预览阶段时,我们不建议在生产中使用此功能。要学习;了解更多信息,请参阅预览功能。

2

填充<version>占位符并运行以下kubectl命令,将所选版本的Kubernetes Operator部署到Kubernetes集群:

kubectl apply -f https://raw.githubusercontent.com/mongodb/mongodb-kubernetes/1.2.0/public/mongodb-kubernetes.yaml
3

填充<version>占位符并运行以下kubectl命令,将所选的 CRD 版本部署到Kubernetes集群:

kubectl apply -f https://raw.githubusercontent.com/mongodb/mongodb-kubernetes/1.2.0/public/crds.yaml

使用 适用于Kubernetes的MongoDB Helm Charts 。

1

您可以通过运行以下命令在本地添加Kubernetes Operator Helm Chart:

helm repo add mongodb https://mongodb.github.io/helm-charts
2

要学习;了解可选的 Kubernetes Operator 安装设置,请参阅Operator Helm 安装设置。

3

使用所需的Kubernetes Operator 版本运行以下kubectl命令,将 CRD部署到Kubernetes集群:

kubectl apply -f https://raw.githubusercontent.com/mongodb/mongodb-kubernetes/1.2.0/public/crds.yaml
4

运行以下helm命令,将Kubernetes Operator部署到Kubernetes集群中的默认命名空间:

helm upgrade --install mongodb-kubernetes-operator mongodb/mongodb-kubernetes

您可以传递--namespace--create-namespace标志,将Kubernetes Operator部署到非默认命名空间,如下所示:

helm upgrade --install mongodb-kubernetes-operator mongodb/mongodb-kubernetes \
--namespace mongodb \
--create-namespace

MongoDB 每天都会重建 Kubernetes 操作符映像,以集成最新的安全和操作系统更新。

默认情况下, helm安装您指定的 Kubernetes 操作符版本的最新版本。

要安装较早的版本,请使用--set build=<build-id>将版本 ID 指定为参数。 版本 ID 的格式始终为-b<YYYYMMDD>T000000Z ,其中<YYYYMMDD>是要使用的版本的创建日期。

例子

此示例展示了如何使用最新映像安装 Kubernetes 操作符:

helm install mongodb-kubernetes-operator mongodb/mongodb-kubernetes

此示例展示了如何使用 2021 年 2 月 5 日午夜创建的映像安装 Kubernetes 操作符:

helm install mongodb-kubernetes-operator mongodb/mongodb-kubernetes \
--set build=-b20210205T000000Z

注意

MongoDB 建议使用默认(最新)版本。

开始之前,请确保在将Kubernetes Operator部署到OpenShift时将MANAGED_SECURITY_CONTEXT标志设立为true 。 该值预定义在 values-openshift.yaml 文件。

安装过程因您想要配置环境的方式而异:

注意

自始至终使用相同的命名空间

By default, the Kubernetes Operator deploys all resources in your Kubernetes cluster to the namespace mongodb. You can deploy Kubernetes Operator resources to a different namespace by editing all values for metadata.namespace in mongodb-kubernetes-openshift.yaml. You must also update the subjects[0].namespace value in every RoleBinding and ClusterRoleBinding in the same file. If you omit this value, the bindings look for the ServiceAccount in the default mongodb namespace and can't find it:

---
apiVersion: v1
kind: ServiceAccount
metadata:
name: mongodb-kubernetes-operator
namespace: production
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: mongodb-kubernetes-operator
namespace: production
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: mongodb-kubernetes-operator
subjects:
- kind: ServiceAccount
name: mongodb-kubernetes-operator
namespace: production
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-kubernetes-operator
namespace: production
---
# Example truncated
---
...
1

调用以下 git 命令:

git clone https://github.com/mongodb/mongodb-kubernetes.git
2

例如,如果您将存储库克隆到主目录中,请运行:

cd ~/mongodb-kubernetes
3

调用以下oc命令:

oc apply -f crds.yaml
4

要了解可选的 Kubernetes Operator 安装设置,请参阅Operator kubectl 和 oc 安装设置。

注意

要启用静态容器的公共预览版以提高和简化安全性,请参阅静态容器(公共预览版)。当此功能处于公共预览阶段时,我们不建议在生产中使用此功能。要学习;了解更多信息,请参阅预览功能。

5
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: enterprise-operator
namespace: mongodb
imagePullSecrets:
- name: <openshift-pull-secret>
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: mongodb-kubernetes-appdb
namespace: mongodb
imagePullSecrets:
- name: <openshift-pull-secret>
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: mongodb-kubernetes-database-pods
namespace: mongodb
imagePullSecrets:
- name: <openshift-pull-secret>

要了解更多信息,请参阅Helm 安装设置中的registry.imagePullSecrets设置。

6

调用以下oc命令:

oc apply -f mongodb-kubernetes-openshift.yaml

使用 适用于Kubernetes的MongoDB Helm Charts 。

You can install the Kubernetes Operator with Helm 3.

1
helm repo add mongodb https://mongodb.github.io/helm-charts
2

安装适用于Kubernetes的MongoDB Helm Charts:

helm install mongodb-kubernetes-operator mongodb/mongodb-kubernetes \
--values https://raw.githubusercontent.com/mongodb/helm-charts/main/charts/mongodb-kubernetes/values-openshift.yaml

使用values-openshift.yaml设置。要学习;了解可选的Kubernetes Operator 安装设置,请参阅 Operator Helm 安装设置。

注意

要启用静态容器的公共预览版以提高和简化安全性,请参阅静态容器(公共预览版)。当此功能处于公共预览阶段时,我们不建议在生产中使用此功能。要学习;了解更多信息,请参阅预览功能。

MongoDB 每天都会重建 Kubernetes 操作符映像,以集成最新的安全和操作系统更新。

默认情况下, helm安装您指定的 Kubernetes 操作符版本的最新版本。

要安装较早的版本,请使用--set build=<build-id>将版本 ID 指定为参数。 版本 ID 的格式始终为-b<YYYYMMDD>T000000Z ,其中<YYYYMMDD>是要使用的版本的创建日期。

例子

此示例展示了如何使用最新映像安装 Kubernetes 操作符:

helm install mongodb-kubernetes-operator mongodb/mongodb-kubernetes

此示例展示了如何使用 2021 年 2 月 5 日午夜创建的映像安装 Kubernetes 操作符:

helm install mongodb-kubernetes-operator mongodb/mongodb-kubernetes \
--set build=-b20210205T000000Z

注意

MongoDB 建议使用默认(最新)版本。

要验证 Kubernetes 操作符是否正确安装,请运行以下命令并验证输出:

kubectl describe deployments mongodb-kubernetes-operator -n <metadata.namespace>
oc describe deployments mongodb-kubernetes-operator -n <metadata.namespace>

默认情况下,部署存在于mongodb命名空间中。 如果出现以下错误消息,请确保使用正确的命名空间:

Error from server (NotFound): deployments.apps "mongodb-kubernetes-operator" not found

要对 Kubernetes 操作符进行故障排除,请参阅查看 Kubernetes 操作符的日志和其他故障排除主题。

重要

如果需要删除 Kubernetes 操作符 或命名空间,则必须首先删除 MongoDB 资源。

安装MongoDB Controllers for Kubernetes Operator 后,您可以: