'How to connect to MongoDB replicaset on Kubernetes
I have deployed bitnami's Mongodb helm chart in the replicaset mode on a K8s cluster, using this minimal config (for now):
architecture: replicaset
auth:
enabled: false
Now I have two replicas (one primary and one secondary, allegedly) and an arbiter (no data, just voting rights). Additionally, I got two services: appname-mongodb-headless, appname-mongodb-arbiter-headless. However, the MongoDB docs specify the connection string in case of replicaset installations as mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myRepl.
I can use mongodb://appname-mongodb-headless:27017 to connect to the db, but is it the "real experience" (i.e. highly available, etc)?
- Do I need to specify the replicaset name (as in the example) and how do I find out what it is?
- If the current services are enough, do I need to include the arbiter in the connection string?
- Or should I create separate services for each replica and build the recommended connection string?
externalAccess: enabled: true autoDiscovery: enabled: true - I will eventually enable authentication after sorting out this part of the connection. What is this
replicaSetKey("Key used for authentication in the replicaset"), and where do I use it?
I found this similar question. It is for another chart, but it suggests me that some combination of the headless services should be enough. Nonetheless, it doesn't answer all aspects of my question.
Solution 1:[1]
Adding to Marcos' answer, there is another URI format called DNS Seed List Connection Format from 3.6+ which you can use with a single host name of your headless service and still take advantage of the replicaset.
mongodb+srv://server.example.com/
It is described here: https://docs.mongodb.com/manual/reference/connection-string/#dns-seed-list-connection-format
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel Arechiga |
