The following procedure outlines how to upgrade the Kubernetes Operator to its latest version. This upgrade process parallels the Kubernetes Operator installation process.
Upgrade the MongoDB Controllers for Kubernetes Operator Running in Kubernetes
Note
Use the same namespace throughout
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: v1kind: ServiceAccountmetadata: name: mongodb-kubernetes-operator namespace: production
apiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingmetadata: name: mongodb-kubernetes-operator namespace: productionroleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: mongodb-kubernetes-operatorsubjects: - kind: ServiceAccount name: mongodb-kubernetes-operator namespace: production
apiVersion: apps/v1kind: Deploymentmetadata: name: mongodb-kubernetes-operator namespace: production
# Example truncatedCustomize your Kubernetes Operator YAML before upgrading it.
If needed, find the appropriate example deployment YAML file for your chosen version of the Kubernetes Operator in the GitHub repository. Then, to avoid breaking changes, customize the example YAML file to match the configuration details of your currently deployed Kubernetes Operator.
Upgrade to the new version of the Kubernetes Operator.
Deploy your customized Kubernetes Operator by running the following:
kubectl apply -f <customized-operator-yaml-file>.yamlIf you do not need to modify the provided deployment YAML, you can apply it directly as follows:
Multi-Cluster
kubectl apply -f https://raw.githubusercontent.com/mongodb/mongodb-kubernetes/1.15.0/public/mongodb-kubernetes-multi-cluster.yamlSingle-Cluster
kubectl apply -f https://raw.githubusercontent.com/mongodb/mongodb-kubernetes/1.15.0/public/mongodb-kubernetes.yamlUse the MongoDB Helm Charts for Kubernetes.
Update to the latest version of the MongoDB Helm Charts for Kubernetes.
Run the following command to check the version of your current Helm template:
helm search repo mongodb/mongodb-kubernetesIf your currently installed version is not the latest release, run the following commmand to update your Helm repo:
helm repo update mongodbIf you don't have the Helm repo installed locally, you can install it by running:
helm repo add mongodb https://mongodb.github.io/helm-chartsCustomize your Helm Chart before upgrading it.
To avoid breaking changes, you should ensure that you select the same settings as those in your existing deployment. To learn about optional Kubernetes Operator installation settings, see Operator Helm Installation Settings.
Upgrade the Kubernetes Operator.
Run the following helm command to deploy the Kubernetes Operator to the default namespace in your Kubernetes cluster:
helm upgrade --install mongodb-kubernetes-operator mongodb/mongodb-kubernetesYou can pass the --namespace and --namespace-create flags to deploy the Kubernetes Operator to a non-default namespace, like so:
helm upgrade --install mongodb-kubernetes-operator mongodb/mongodb-kubernetes \--namespace mongodb \--create-namespaceUpgrade the MongoDB Controllers for Kubernetes Operator Running in OpenShift
The following steps depend on how your environment is configured:
Note
Use the same namespace throughout
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: v1kind: ServiceAccountmetadata: name: mongodb-kubernetes-operator namespace: production
apiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingmetadata: name: mongodb-kubernetes-operator namespace: productionroleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: mongodb-kubernetes-operatorsubjects: - kind: ServiceAccount name: mongodb-kubernetes-operator namespace: production
apiVersion: apps/v1kind: Deploymentmetadata: name: mongodb-kubernetes-operator namespace: production
# Example truncatedCustomize the Kubernetes Operator YAML before upgrading it.
To avoid breaking changes, you should ensure that you select the same settings as those in your existing deployment. To learn about optional Kubernetes Operator installation settings, see Operator Helm Installation Settings.
You must add your <openshift-pull-secret> to the ServiceAccount definitions:
apiVersion: v1kind: ServiceAccountmetadata: name: enterprise-operator
namespace: mongodb
imagePullSecrets: - name: <openshift-pull-secret>
apiVersion: v1kind: ServiceAccountmetadata: name: mongodb-kubernetes-appdb
namespace: mongodb
imagePullSecrets: - name: <openshift-pull-secret>
apiVersion: v1kind: ServiceAccountmetadata: name: mongodb-kubernetes-database-pods
namespace: mongodb
imagePullSecrets: - name: <openshift-pull-secret>Upgrade the CustomResourceDefinitions for MongoDB deployments.
Run the following oc command:
Run the following oc command to deploy your chosen version of the CRDs to your Kubernetes cluster:
oc apply -f https://raw.githubusercontent.com/mongodb/mongodb-kubernetes/1.15.0/public/crds.yamlUpgrade to the new version of the Kubernetes Operator.
Run the following oc command to deploy your chosen version of the Kubernetes Operator to your Kubernetes cluster:
oc apply -f https://raw.githubusercontent.com/mongodb/mongodb-kubernetes/1.15.0/public/mongodb-kubernetes-openshift.yamlUpdate to the latest version of the MongoDB Helm Charts for Kubernetes.
Run the following command to check the version of your current Helm template:
helm search repo mongodb/mongodb-kubernetesIf your currently installed version is not the latest release, run the following commmand to update your Helm repo:
helm repo update mongodbIf you don't have the Helm repo installed locally, you can install it by running:
helm repo add mongodb https://mongodb.github.io/helm-chartsCustomize your Helm Chart before upgrading it.
To avoid breaking changes, you should ensure that you select the same settings as those in your existing deployment. To learn about optional Kubernetes Operator installation settings, see Operator Helm Installation Settings.
Upgrade the Kubernetes Operator.
Run the following helm command to deploy the Kubernetes Operator to the default namespace in your Kubernetes cluster:
helm upgrade --install mongodb-kubernetes-operator mongodb/mongodb-kubernetesYou can pass the --namespace and --namespace-create flags to deploy the Kubernetes Operator to a non-default namespace, like so:
helm upgrade --install mongodb-kubernetes-operator mongodb/mongodb-kubernetes \--namespace mongodb \--create-namespaceTo troubleshoot your Kubernetes Operator, see Review Logs from the Kubernetes Operator and other troubleshooting topics.
Important
If you need to remove the Kubernetes Operator or the namespace, you first must remove MongoDB resources.
Verify the Installation
To verify that the Kubernetes Operator installed correctly, run the following command and verify the output:
kubectl describe deployments mongodb-kubernetes-operator -n <metadata.namespace>oc describe deployments mongodb-kubernetes-operator -n <metadata.namespace>By default, deployments exist in the mongodb namespace. If the following error message appears, ensure you use the correct namespace:
Error from server (NotFound): deployments.apps "mongodb-kubernetes-operator" not foundTo troubleshoot your Kubernetes Operator, see Review Logs from the Kubernetes Operator and other troubleshooting topics.
Important
If you need to remove the Kubernetes Operator or the namespace, you first must remove MongoDB resources.
Next Steps
After upgrading the MongoDB Controllers for Kubernetes Operator, you can: