Home > Enterprise >  MongoDB docker version migration from 4.4.18 to 6.0 always CrashLoopBackOff
MongoDB docker version migration from 4.4.18 to 6.0 always CrashLoopBackOff

Time:12-07

Small question regarding MongoDB please.

I am currently using the version 4.4.18 of MongoDB

I am deploying it using this manifest in Kubernetes, and no problem at all, everything is working fine, very happy.

apiVersion: v1
kind: ConfigMap
metadata:
  name: mongo-config
data:
  mongo.conf: |
    storage:
      dbPath: /data/db
  ensure-users.js: |
    const targetDbStr = 'test';
    const rootUser = cat('/etc/k8-test/admin/MONGO_ROOT_USERNAME');
    const rootPass = cat('/etc/k8-test/admin/MONGO_ROOT_PASSWORD');
    const usersStr = cat('/etc/k8-test/MONGO_USERS_LIST');
    const adminDb = db.getSiblingDB('admin');
    adminDb.auth(rootUser, rootPass);
    print('Successfully authenticated admin user');
    const targetDb = db.getSiblingDB(targetDbStr);
    const customRoles = adminDb
      .getRoles({rolesInfo: 1, showBuiltinRoles: false})
      .map(role => role.role)
      .filter(Boolean);
    usersStr
      .trim()
      .split(';')
      .map(s => s.split(':'))
      .forEach(user => {
        const username = user[0];
        const rolesStr = user[1];
        const password = user[2];
        if (!rolesStr || !password) {
          return;
        }
        const roles = rolesStr.split(',');
        const userDoc = {
          user: username,
          pwd: password,
        };
        userDoc.roles = roles.map(role => {
          if (!~customRoles.indexOf(role)) {
            return role;
          }
          return {role: role, db: 'admin'};
        });
        try {
          targetDb.createUser(userDoc);
        } catch (err) {
          if (!~err.message.toLowerCase().indexOf('duplicate')) {
            throw err;
          }
        }
      });
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongo
spec:
  serviceName: mongo
  replicas: 1
  selector:
    matchLabels:
      app: mongo
  template:
    metadata:
      labels:
        app: mongo
    spec:
      terminationGracePeriodSeconds: 30
      containers:
        - name: mongo
          image: docker.io/mongo:4.4.18
#          image: docker.io/mongo:6.0
          command: ["/bin/sh"]
          args: ["-c", "mongod --replSet=rs0 --bind_ip_all"]
          resources:
            limits:
              cpu: 1000m
              memory: 1G
            requests:
              cpu: 100m
              memory: 1G
          ports:
            - containerPort: 27017
              name: mongo
              protocol: TCP
          volumeMounts:
            - name: data
              mountPath: /data/db
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: [ "ReadWriteOnce" ]
        storageClassName: nfs-1
        resources:
          requests:
            storage: 50Mi
---
apiVersion: v1
kind: Service
metadata:
  name: mongo
  labels:
    app: mongo
spec:
  selector:
    app: mongo
  ports:
    - port: 27017
      targetPort: 27017
      name: mongo
  clusterIP: None

Now, I just want to bump the version up to 6.0, literally just replacing this one line (the one commented out), leaving everything else exactly the same.

I then deploy this new version, and unfortunately, this happens.

NAME          READY   STATUS             RESTARTS      AGE
pod/mongo-0   0/1     CrashLoopBackOff   1 (10s ago)   24s

When tailing the log, I do see:

{"t":{"$date":"2022-12-07T06:50:10.048 00:00"},"s":"F",  "c":"CONTROL",  "id":20573,   "ctx":"initandlisten","msg":"Wrong mongod version","attr":{"error":"UPGRADE PROBLEM: Found an invalid featureCompatibilityVersion document (ERROR: Location4926900: Invalid featureCompatibilityVersion document in admin.system.version: { _id: \"featureCompatibilityVersion\", version: \"4.2\" }. See https://docs.mongodb.com/master/release-notes/5.0-compatibility/#feature-compatibility. :: caused by :: Invalid feature compatibility version value, expected '5.0' or '5.3' or '6.0. See https://docs.mongodb.com/master/release-notes/5.0-compatibility/#feature-compatibility.). If the current featureCompatibilityVersion is below 5.0, see the documentation on upgrading at https://docs.mongodb.com/master/release-notes/5.0/#upgrade-procedures."}}

I went to read the docs, but it is mainly about migrating to 5.0. May I ask what am I missing for 6.0 please?

Thank you

CodePudding user response:

The error is due to mongodb version is not compatible with data files mounted to /data/db.

The gap between version is too large. As @WernfriedDomscheit commented you will need to upgrade it by steps:

If the dataset size allows, you can shortcut it by backing up your data from v4.4, starting v6 with new empty volume mounted to /data/db, and restoring the database from the backup.

  • Related