Is this a request for help?:
Is this a BUG REPORT or FEATURE REQUEST? (choose one): NONE
Version of Helm and Kubernetes: 1.12.4, 2.11
Which chart: stable/mongodb-replicaset
Is there a way to connect to a mongodb-replicaset inside the cluster using only one URL? Would I achieve the same thing by using the kubernetes service URL as passing in all 3 of my mongodb replica's hostnames separated by a comma? What's the best approach here?
Does the chart enable me somehow to leverage the DNS Seedlist Connection so I can do something like mongod+srv?
I tried looking for documentation as to how to connect to the replicaSet deployed by the chart, but I couldn't find what I was looking for.
I suggest you to deploy mongodb manually. Most of helm charts are not well maintained, I don't think you can find useful answers here. About documentation there is no such thing in helm chart. You'll run into even more issues when you need to change configs, or update your deployment etc.
Answer to your question: I believe you can access Mongodb-replicaset by its service name. Example if you named your service mongodb-replicaset then your connection uri will be something like:
mongodb://username:password@mongodb-replicaset:27017/databasename?authSource=admin&replicaSet=rs0
etc. But I'm not 100% sure it's correct approach, but it works for me. But same uri doesn't work when using mongorestore or mongodump. You can use full service names there.
If you're using a MongoDB replica set aware client, you can construct a MongoDB URI with the service and it is smart enough to retrieve the list of all MongoDB nodes. If your client is not MongoDB rs aware and expects a single primary, you may have trouble with writes as it will randomly connect to a primary or secondary. See #1569.
A correction to @shinebayar-g is that you should use the -client service to connect. The service is generally named ${release}-mongodb-replicaset-client. Also, you shouldn't generally use credentials in the URI but pass as options.
mongodb://release-mongodb-replicaset-client:27017/databasename?authSource=admin&replicaSet=rs0
You should be able to use mongodb+srv protocol, but I have not tried it.
@steven-sheehy Thank you for the information. Where can I find more information about the -client service?
@brianupskill kubectl get services -o wide or the service template.
@steven-sheehy Sorry, I meant to ask if there's any documentation where it outlines connecting to the -client service vs the regular service.
No, the regular service is an internal service that tolerates unready endpoints. For your clients, you don't want to see unready pods so use the -client service. Otherwise they are identical.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any further update will cause the issue/pull request to no longer be considered stale. Thank you for your contributions.
This issue is being automatically closed due to inactivity.
@steven-sheehy
i am trying to use client service inside k8s cluster as suggested by you but i am getting following error.
i am using mongodb-replicaset as sub chart and my release name is skeleton
URL i am using from application
`val mongoUri = "mongodb://myuser:mydbpwd@skeleton-mongodb-replicaset-client:27001/skeleton?authSource=admin&replicaSet=rs0"
`
[1;30m2019-04-28 14:34:34,483 [0;39m => [34mINFO [0;39m [ [32mlocalhost-startStop-1 [0;39m] [33mcom.mongodb.diagnostics.logging.SLF4JLogger [0;39m: Cluster created with settings {hosts=[skeleton-mongodb-replicaset-client:27001], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[1;30m2019-04-28 14:34:34,485 [0;39m => [34mINFO [0;39m [ [32mlocalhost-startStop-1 [0;39m] [33mcom.mongodb.diagnostics.logging.SLF4JLogger [0;39m: Adding discovered server skeleton-mongodb-replicaset-client:27001 to client view of cluster
[1;30m2019-04-28 14:34:34,984 [0;39m => [34mINFO [0;39m [ [32mcluster-ClusterId{value='5cc5b9fab13658000122961a', description='null'}-skeleton-mongodb-replicaset-client:27001 [0;39m] [33mcom.mongodb.diagnostics.logging.SLF4JLogger [0;39m: Exception in monitor thread while connecting to server skeleton-mongodb-replicaset-client:27001
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.netty.NettyStream$2.operationComplete(NettyStream.java:158)
at com.mongodb.connection.netty.NettyStream$2.operationComplete(NettyStream.java:145)
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:511)
at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:504)
at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:483)
can you please suggest any pointers if i am missing something
Most helpful comment
If you're using a MongoDB replica set aware client, you can construct a MongoDB URI with the service and it is smart enough to retrieve the list of all MongoDB nodes. If your client is not MongoDB rs aware and expects a single primary, you may have trouble with writes as it will randomly connect to a primary or secondary. See #1569.
A correction to @shinebayar-g is that you should use the -client service to connect. The service is generally named ${release}-mongodb-replicaset-client. Also, you shouldn't generally use credentials in the URI but pass as options.
You should be able to use mongodb+srv protocol, but I have not tried it.