Unable to expose mongodb replicaset to nodeport Kubernetes

Description:

Hello,

Could you please suggest a functional solution? I’m trying, like several other people I imagine, to expose my MongoDB replica set on the NodePorts of my Kubernetes cluster so that I can connect other components of my infrastructure (outside Kubernetes) to my database.

I’ve tried exposing the pods of my replica set via the options in the cr.yaml file

Steps to Reproduce:

expose:
enabled: true
exposeType: NodePort

Version:

i’m using version v1.15.0 of the cr.yaml. However, when I attempt to connect, I always get this type of error:

Logs:

mongodb://@172.16.0.33:30786,172.16.0.4:31907,172.16.0.33:30301/admin?replicaSet=rs0&ssl=false&appName=mongosh+2.0.0
“MongoNetworkError: getaddrinfo ENOTFOUND test1-mongodb-rs0-0.test1-mongodb-rs0.test1-mongo.svc.cluster.local”

After researching, I feel like I’m in the same situation as here: Connection to an exposed replicaset is not working and here: Connection Issues When Accessing MongoDB Replica Set from Outside the Kubernetes Cluster.

What is the solution for this to work, please?

Seems we need to make our expose doc clearer :slight_smile:

The secret souce here would be adding the following:

clusterServiceDNSMode: External

Read more here: Exposing the cluster - Percona Operator for MongoDB