bitnami / charts

Bitnami Helm Charts
https://bitnami.com
Other
9.07k stars 9.24k forks source link

custom username, password and databasename to be passed during helm install command #10483

Closed Shilagrawal closed 2 years ago

Shilagrawal commented 2 years ago

Name and Version

Latest mongo db releae 4.1.12, 4..3

What steps will reproduce the bug?

I have been trying to see if I can create a database user in each pod during the helm install command itself earlier (2 months back ) I had used mongodbUsername, mongodbPassword, mongodbaDatabase which was easy to create a user in DB during the helm command itself

I am trying to find ways to create one in the most effective way so that if I have more shards (say 16 or all) all of them are taken care of.

MongoDB sharded deployment: the command I had been using is not working now for custom DB users:

helm install my-release bitnami/mongodb-sharded --namespace=mongodb \
--set global.storageClass=vxflexos-xfs \
--set mongodbRootPassword=mongodb123,mongodbUsername=mongodb,mongodbPassword=mongodb123,mongodbDatabase=ycsb \
--set volumePermissions.enabled=true \
--set replicaSet.enabled=true \
--set shards=8 \
--set configsvr.replicas=1 \
--set configsvr.persistence.size=100Gi \
--set mongos.replicas=1 \
--set shardsvr.dataNode.replicas=1 \
--set shardsvr.persistence.size=1.5Ti \
--set shardsvr.dataNode.resources.requests.memory=64Gi \
--set shardsvr.dataNode.resources.requests.cpu=16 \
--set configsvr.resources.requests.memory=16Gi \
--set mongos.resources.requests.memory=16Gi

What is the expected behavior?

Looking forward to a way to create a custom DB user, password, and database name for all pods in one go.

What do you see instead?

custom username /cred and details don't take effect at startup

Shilagrawal commented 2 years ago

@carrodher
I have referred #1655 however didnt get the initscript part completely as to where can i add the lines in values.yaml

carrodher commented 2 years ago

You need to create an external k8s ConfigMap (CM) with the script you would like to execute, then use the common.initScriptsCM parameter to pass the name of the CM you created to the Helm chart in order to be taken into account.

See https://github.com/bitnami/charts/tree/master/bitnami/mongodb-sharded#initialize-a-fresh-instance

mmosierteamvelocity commented 2 years ago

Can user information be stored and accessed in a secret as well? Or just via a script in a configmap? @carrodher

carrodher commented 2 years ago

There are several parameters such as

You can find all the parameters listed in the README or in the values.yaml

github-actions[bot] commented 2 years ago

This Issue has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thanks for the feedback.

github-actions[bot] commented 2 years ago

Due to the lack of activity in the last 5 days since it was marked as "stale", we proceed to close this Issue. Do not hesitate to reopen it later if necessary.

leqduyvp commented 2 years ago

@carrodher Can you give an example for mongodb-passwords secrets and mongodb-databases values. I tried to initialize a database with config like this but it didn't work.

auth:
  usernames: ["user"]
  databases: ["init"]
migruiz4 commented 2 years ago

Hi @leqduyvp,

Could you please provide more details about your issue?

Using those values and the latest value of the bitnami/mongodb chart, I was able to access the init database using the user user:

I have no name!@test-mongodb-6b988f7799-skvhn:/$ mongosh  mongodb://127.0.0.1:27017/init -u user -p 1QAzSVvf6l 
Current Mongosh Log ID: 62d1671737d79147247ea3d6
Connecting to:          mongodb://<credentials>@localhost/init?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.5.0
Using MongoDB:          5.0.9
Using Mongosh:          1.5.0

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

init> 

You can confirm the user creation by checking the MongoDB pod logs, you should see a message like this:

mongodb 13:02:12.35 INFO  ==> Creating users...
mongodb 13:02:12.35 INFO  ==> Creating root user...
mongodb 13:02:14.49 INFO  ==> Creating user 'user'...
mongodb 13:02:16.63 INFO  ==> Users created

If you have not provided a password using auth.passwords, you can get the autogenerated password using the following command (replacing the values with <>):

kubectl get secret --namespace <my_namespace> <my_release>-mongodb -o jsonpath="{.data.mongodb-passwords}" | base64 -d | awk -F',' '{print $1}'