Connection Issues When Accessing MongoDB Replica Set from Outside the Kubernetes Cluster

Description:

Hello!

I have created a replica set of 3 and exposed the db cluster using the following configuration in the cr.yaml:

expose:
  enabled: true
  exposeType: LoadBalancer

I am able to connect to the database from outside the k8s cluster using a direct connection without any issues. However, the problem arises when I attempt to connect to the entire replica set from outside the k8s cluster using the following command:

mongosh "mongodb://<LB_IP_0>,<LB_IP_1>,<LB_IP_2>/admin?replicaSet=rs0&ssl=false"

Unfortunately, this action results in an error:

MongoNetworkError: getaddrinfo ENOTFOUND mongodb-test-rs0-1.mongodb-test-rs0.mongodb-test.svc.cluster.local

From my understanding, this error has arisen because mongosh’s mode of connection to the remote database first utilizes the seed list (<LB_IP_0>,<LB_IP_1>,<LB_IP_2>) to connect to any one of the instances. It then retrieves the information regarding who the primary is and the list of hosts returned by the rs.isMaster() command. After this, it discards the initial seed list provided in the connection string and employs the list of hosts from the rs.isMaster() command. Since those hosts can only be accessed from inside the k8s cluster, this results in the error.

My question is - am I missing something in my configuration? If not, is the only possible way to properly expose the Replica Set is to set clusterServiceDNSMode: "External"?

Version:

1.14.0

We are having the same problem and we had to switch to clusterServiceDNSMode: "External" to resolve the issue.

Hey!

Yes, we have it tracked here: [K8SPSMDB-929] Can't connect to MongoDB Replica Set via LoadBalancer - Percona JIRA