DEV Community

Thodoris Velmachos
Thodoris Velmachos

Posted on

Do you want to upgrade MongoDB from version 5 to 7 on K8s?

Are you wondering how you can upgrade MongoDB from version 5 to 7 without affecting old MongoDB instance and without spending time and resource to migrate the data from the old MongoDB instance to the new one?

The answer to the question at least regarding the data is Velero, as you can see from the following snippet I am using Velero to take incremental snapshots of the stateful workloads running in the K8s Clusters (GKE) and helm to deploy a new instance of MongoDB (just to mention the values found bellow is just for testing), it goes without saying that if you want to deploy any workload to K8s you will use Gitops tools like FluxCD / ArgoCD instead of just deploy them imperatively using the cli tools helm, kubectl.

# Clone Volume
1. velero restore create test-mongorestore-only-pvc-pv --include-resources PersistentVolume,PersistentVolumeClaim --from-backup backup-app-mongodb-auto-20240719020007 --namespace-mappings default:dblabs
2. 
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm upgrade --install test-mongo-upgrade-7 bitnami/mongodb --version 12.1.31 -f values.yaml
---
image:
  tag: "6.0"
auth:
  enabled: true
  rootPassword: "<same pass>"
persistence:
  enabled: true
  existingClaim: datadir-mongodb-0
3. Set featureCompatibilityVersion = 6.0
db.adminCommand({ setFeatureCompatibilityVersion: "6.0" });
db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } ).featureCompatibilityVersion.version
4 helm upgrade --install test-mongo-upgrade-6 my-repo/mongodb --version 12.1.31 -f values.yaml
---
image:
  tag: "7.0"
auth:
  enabled: true
  rootPassword: "<same pass>"
persistence:
  enabled: true
  existingClaim: datadir-mongodb-0
5. Set featureCompatibilityVersion = 7.0
db.adminCommand({ setFeatureCompatibilityVersion: "7.0", confirm: true });
db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } ).featureCompatibilityVersion.version
Enter fullscreen mode Exit fullscreen mode

More information can be found in the following links

https://www.digitalocean.com/community/questions/mongodb-updated-this-morning-to-7-0-1-now-wont-restart

https://www.mongodb.com/docs/manual/reference/command/setFeatureCompatibilityVersion/
Enter fullscreen mode Exit fullscreen mode

I hope it helps. Cheers!

Top comments (0)