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

升级Kubernetes Operator 的MongoDB控制器

以下过程概述了如何将Kubernetes Operator升级到最新版本。 此升级进程与Kubernetes Operator 安装进程并行。

注意

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

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

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

运行以下命令,检查当前 Helm 模板的版本:

helm search repo mongodb/mongodb-kubernetes

如果当前安装的版本不是最新版本,请运行以下命令来更新Helm 存储库:

helm repo update mongodb

如果本地没有安装 Helm 存储库,可以通过运行以下命令来安装:

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

为避免破坏性更改,应确保选择与现有部署中的设置相同的设置。 要学习;了解可选的 Kubernetes Operator 安装设置,请参阅Operator Helm 安装设置。

3

填充<version>占位符并运行以下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 install mongodb-kubernetes-operator mongodb/mongodb-kubernetes

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

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

以下步骤取决于环境的配置方式:

注意

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

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

为避免破坏性更改,应确保选择与现有部署中的设置相同的设置。 要学习;了解可选的 Kubernetes Operator 安装设置,请参阅Operator Helm 安装设置。

您必须将<openshift-pull-secret>添加到ServiceAccount定义中:

---
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>
2

填充 <version> 占位符并运行以下 oc

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

运行以下oc命令:

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

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

运行以下命令,检查当前 Helm 模板的版本:

helm search repo mongodb/mongodb-kubernetes

如果当前安装的版本不是最新版本,请运行以下命令来更新Helm 存储库:

helm repo update mongodb

如果本地没有安装 Helm 存储库,可以通过运行以下命令来安装:

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

为避免破坏性更改,应确保选择与现有部署中的设置相同的设置。 要学习;了解可选的 Kubernetes Operator 安装设置,请参阅Operator Helm 安装设置。

3

填充<version>占位符并运行以下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 install mongodb-kubernetes-operator mongodb/mongodb-kubernetes

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

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

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

重要

如果需要删除 Kubernetes 操作符 或命名空间,则必须首先删除 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 后,您可以: