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
More information can be found in the following links
I hope it helps. Cheers!
Subscribe to my newsletter
Read articles from Thodoris Velmachos directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Thodoris Velmachos
Thodoris Velmachos
I am DevOps Engineer from Greece,I also founder of NgCloudOps is providing DevOps and Cloud Consulting Services. I love to work with cutting edge technologies like Kubernetes and of course with other Cloud Native Projects, I love building Continues Delivery Solutions with the use of Flux and ArgoCD. More information about me can be found in the following url: https://t-velmachos.start.page/