Search code examples
mongodbgoogle-kubernetes-enginekubectl

MongoDB statefulset updating


I am in the process of deploying a mongodb ReplicaSet on GKE.

My deployment works, however I would like to enable auth on Mongo.

I have connected to my pod

kubectl exec -it {pod_name} mongo admin

Created an Admin user and also a user for my database. I was then thinking I could update mongo-statefulset.yaml with the --auth flag and apply the updated yaml.

Something like

.....
spec:
      terminationGracePeriodSeconds: 10
      containers:
        - name: mongod-container
          image: mongo:3.6
          command:
            - mongod
            - "--bind_ip"
            - "0.0.0.0"
            - "--replSet"
            - rs0
            - "--smallfiles"
            - "--noprealloc"
            - "--auth"
          ports:
            - containerPort: 27017
          volumeMounts:
            - name: mongo-persistent-storage
              mountPath: /data/db
.....

But running kubectl apply -f mongo-statefulset.yaml just produces

service/mongo-svc unchanged

statefulset.apps/mongo configured

Should I restart my pods for this to now take effect?


Solution

  • Try to do rolling update: The RollingUpdate update strategy will update all Pods in a StatefulSet, in reverse ordinal order, while respecting the StatefulSet guarantees.

    Patch the web StatefulSet to apply the RollingUpdate update strategy.

    $ kubectl patch statefulset your_statefulset_name -p '{"spec":{...}}}'
    

    Don't to forget to add env label with credentials you have created on your pod like:

          env:
            - name: MONGODB_USERNAME
              value: admin
            - name: MONGODB_PASSWORD
              value: password
    

    I hope it helps.