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

为Kubernetes Operator 安装MongoDB控制器

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

注意

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

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

注意

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

默认情况下,Kubernetes Operator 会将 Kubernetes 集群中的所有资源部署到 命名空间 mongodb 中。您可以通过编辑 mongodb-kubernetes.yaml 中的所有 metadata.namespace 值,将 Kubernetes Operator 资源部署到不同的命名空间。您还必须更新同一文件中的每个 RoleBinding 和 ClusterRoleBinding 中的 subjects[0].namespace 值。如果省略此值,绑定将在默认的 mongodb 命名空间中查找 ServiceAccount,但无法找到它:

---
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 安装设置。

注意

To enable the Public Preview of static containers, which improve and simplify security, see Static Containers (Public Preview). We don't recommend using this feature in production while it's in Public Preview. To learn more, see Preview Features.

2

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

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

运行以下 kubectl 命令,将所选版本的 Kubernetes 操作符 部署到 Kubernetes 集群:

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

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

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

注意

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

默认情况下,Kubernetes Operator 会将 Kubernetes 集群中的所有资源部署到 命名空间 mongodb 中。您可以通过编辑 mongodb-kubernetes-openshift.yaml 中的所有 metadata.namespace 值,将 Kubernetes Operator 资源部署到不同的命名空间。您还必须更新同一文件中的每个 RoleBinding 和 ClusterRoleBinding 中的 subjects[0].namespace 值。如果省略此值,绑定将在默认的 mongodb 命名空间中查找 ServiceAccount,但无法找到它:

---
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
cd mongodb-kubernetes
git checkout 1.5.0
2

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

cd ~/mongodb-kubernetes
3

调用以下oc命令:

oc apply -f crds.yaml
4

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

注意

To enable the Public Preview of static containers, which improve and simplify security, see Static Containers (Public Preview). We don't recommend using this feature in production while it's in Public Preview. To learn more, see Preview Features.

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 操作符是否正确安装,请运行以下命令并验证输出:

kubectl 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 后,您可以: