How can we authenticate to a mongodb database created by helm stable/mongo chart (from another pod in the same cluster)?
The "one pod url" mongodb://user:password@mongodb:27017/dbname
does not work because we have to authenticate to the admin pod
According to mongo documentation, we should use something like : mongodb://user:password@mongodb-1,mongodb-2,mongodb-3:27017/dbname
but the chart only creates one service ?!
I tried also to add ?authSource=admin&replicaSet=rs0
at the url but authentication still fails..
Using the stable/mongodb
chart and enabling the replicaSet
option, you should connect to the service hostname <deployment fullname>-mongodb
using the "root"
user and mongodbRootPassword
provided password using the --authenticationDatabase admin
option (or setting authSource=admin
in the connection URL). Example:
kubectl exec -it deployname-mongodb-primary-0 -- mongo dbname -u root -p rootpassword --authenticationDatabase admin
Intstead, if you set mongodbUsername
, mongodbPassword
and mongodbDatabase
, you can connect as non-root user to the configured database; in this case, you should skip the --authenticationDatabase
(or authSource=admin
) option. Example:
kubectl exec -it deployname-mongodb-primary-0 -- mongo -u username -p userpassword
I managed to connect with the following url (only as root) : mongodb://root:<root_password>@mongodb.mongodb:27017/<db_name>?authSource=admin&replicaSet=rs0
with the --authenticationDatabase admin
of the NOTES.txt
converted to authSource=admin
url parameter