MongoDB statefulset updating

6/5/2019

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?

-- Harry Blue
google-kubernetes-engine
kubectl
mongodb

2 Answers

6/6/2019

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.

-- MaggieO
Source: StackOverflow

6/5/2019

You could try

kubectl delete -f mongo-statefulset.yaml && kubectl apply -f mongo-statefulset.yaml
-- DuDoff
Source: StackOverflow