我已经使用 Helm 和图表在 Kubernetes 上部署了 MongoDB ReplicaSet stable/mongodb-replicaset
在 Kubernetes 上,我可以使用类似的连接字符串连接到 MongoDB
mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myRepl
如果我更改副本数,连接字符串也会更改,这也意味着每个连接到数据库的应用程序都需要更新。
有解决方法吗?
我想创建一个服务,这样只需要更改这个,但是连接字符串没有通过正则表达式验证。
对此的任何帮助表示赞赏。
最佳答案
Helm 图表 stable/mongodb-replicaset
还部署了 2 个 headless 服务:
<release name>-mongodb-replicaset
<release name>-mongodb-replicaset-client
<release name>-mongodb-replicaset
的DNS记录返回所有副本的地址,因此,为了连接到副本集,连接字符串是"mongodb+srv://<release name>-mongodb-replicaset.namespace.svc.cluster.local/?tls=false&ssl=false"
请注意,tls 和 ssl 已设置为 false 以进行测试,因为它们默认启用。
关于mongodb - 连接到 Kubernetes 上的 MongoDB ReplicaSet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61490287/