I am unable to change the password of an existing user from MongoDB deployed on k8s, unless I am deleting the database and then recreating it again with the new password.
How can I change the password using the yaml for the mongo stateful object without deleting the db?
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mongo-db-statefulset
namespace: development
spec:
serviceName: mongo-svc
replicas: 1
selector:
matchLabels:
component: mongo
template:
metadata:
labels:
component: mongo
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mongo
image: mongo:4.0.4
volumeMounts:
- mountPath: /data/db
name: volume
ports:
- containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: admin
- name: MONGO_INITDB_ROOT_PASSWORD
# from secrets
value: password
- name: MONGO_INITDB_DATABASE
value: admin
volumes:
- name: volume
persistentVolumeClaim:
claimName: database-persistent-volume-claim