Home > Net >  MongoDB throws authentication error after upgrading chart version with HELM in Kubernetes
MongoDB throws authentication error after upgrading chart version with HELM in Kubernetes

Time:08-24

I tried to upgrade the chart version of MongoDB from 10.1.0 to 11.2.0 since the previous one is outdated. Authentication was not enabled in previous version. But I set the root user password with the upgrade. However, arbiter keep throws authentication errors and mongo pods crash looping.

As I researched it's because of PVC (persistence:true) so when I set it to false and deleted helm releases the installation was successful and pods were running.

But then when using helm3 upgrade the following error occured:

Error: UPGRADE FAILED: cannot patch with kind StatefulSet: StatefulSet.apps is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden

I am trying to figure out to keep persistence:true and set authentication for MongoDB.

values.yaml

mongodb:

  architecture: replicaset
  replicaCount: 2

  podAntiAffinityPreset: hard

  auth:
    enabled: false

  useStatefulSet: true

  persistence:
    enabled: true
    size: 1Gi

  resources:
    limits:
      cpu: 1
      memory: 2Gi
    requests:
      cpu: 100m
      memory: 1Gi

  metrics:
    enabled: true
    livenessProbe:
      enabled: true
    readinessProbe:
      enabled: true

    resources:
      limits:
        cpu: 200m
        memory: 256Mi
      requests:
        cpu: 100m
        memory: 128Mi

gitlab CI

  script:
    - helm3 install
      --namespace="$NAMESPACE"
        --wait
        --timeout $HELM_TIMEOUT

        ..some other stuff..

        --set mongodb.auth.enabled="true"
        --set mongodb.auth.rootPassword="$MONGO_ROOT_PWD_STAGE"
        --set mongodb.auth.replicaSetKey="$MONGO_REPLICA_SET_KEY_STAGE"

        --values ${!HELM_VALUES}
        --kube-context stage
        "$RELEASE_NAME" chart/

Thanks for any help

CodePudding user response:

In K8S Statefulset, unlike Deployment, there are some fields that you cannot change once it is created, you can just change the number of replicas, the template of your pod and the updateStrategy.

So you will get this error if you are changing something in

persistence:
    enabled: true
    size: 1Gi

because it changes the PVC configurations.

To bypass the problem:

  • create a new Statfulset and delete the old one (you can copy the data before delete it)
  • trying to patch the PVC (or any other resource you are trying to change) manually, then apply the helm upgrade command

You can use helm-diff plugin to compare the current revision to the new revision you're trying to create, to understand what's going on.

  • Related