mongodbkuberneteskubernetes-helmbitnami

Helm Chart Bitnami - Replicaset - Database not being created


So trying to create database in a replicaset using helm, using the following values in values.yaml

mongodb:
  architecture: replicaset
  auth:
    rootPassword: "admin"
    usernames: 
      - "user1"
    passwords: 
      - "password1"
    databases: 
      - "mydatabase"
    replicaSetKey: myreplicaKey

Installing the chart using the following command:

helm install sam bitnami/mongodb --set architecture="replicaset",auth.rootPassword=password123 --values values.yaml

Log into my database:

export MONGODB_ROOT_PASSWORD=$(kubectl get secret --namespace default sam-mongodb -o jsonpath="{.data.mongodb-root-password}" | base64 --decode)
kubectl exec -ti sam-mongodb-0 -- mongo --authenticationDatabase admin -u root -p $MONGODB_ROOT_PASSWORD

But cannot see my database called "mydatabase" or specific user "user1" created, I can authenticate with admin user but trying to authenticate to "mydatabase" says failed, so unsure why this is happening, as it works in standalone but not a replicaset.

rs0:PRIMARY> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
rs0:PRIMARY> use admin
switched to db admin
rs0:PRIMARY> show users
{
    "_id" : "admin.root",
    "userId" : UUID("2b74bb99-5e18-434f-8350-9d54eb562230"),
    "user" : "root",
    "db" : "admin",
    "roles" : [
        {
            "role" : "root",
            "db" : "admin"
        }
    ],
    "mechanisms" : [
        "SCRAM-SHA-1",
        "SCRAM-SHA-256"
    ]
}

Was wondering if anyone knew what I might be doing wrong. Thanks


Solution

  • deleted the pvc and re-authenticated, and worked.

    rs0:PRIMARY> use mydatabase
    switched to db mydatabase
    rs0:PRIMARY> db.auth('user1','password1')
    1