Client connection to mongodb replicaset under kubernetes

Hello all,
recently I installed via mongodb operator the mongodb replicaset database.
What I’m not able to do is to connectl from a client to the dataabse.
It is not clera to me if is it necessary to create a specific service and if, how to create it.
Inside the kubernetes cluster the connection works well.
This is an example :

This are the two service I have into my cluster:

root@kubemaster:~/no_helm_mongoDB_under_kubernetes# kubectl get svc -n mongodb
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
example-mongodb-svc ClusterIP None 27017/TCP 27h
mongodb-external LoadBalancer 10.104.139.25 192.168.1.210 27017:32666/TCP 23m

I created mongodb-external and it work inside the cluster.

root@mongo-shell:/# mongosh mongodb://gabriele:gabriele@192.168.1.210:27017/?replicaSet=example-mongodb
Current Mongosh Log ID: 671a043c18cfdd4969fe6910
Connecting to: mongodb://@192.168.1.210:27017/?replicaSet=example-mongodb&appName=mongosh+2.3.2
Using MongoDB: 6.0.5
Using Mongosh: 2.3.2
For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/

The server generated these startup warnings when booting
2024-10-23T04:33:55.818+00:00: vm.max_map_count is too low

example-mongodb [primary] test>

but from an external client I receive following error:

Please enter a MongoDB connection string (Default: mongodb://localhost/): mongodb://gabriele:gabriele@192.168.1.210:27017/?replicaSet=example-mongodb
mongodb://gabriele:gabriele@192.168.1.210:27017/?replicaSet=example-mongodb
Current Mongosh Log ID: 671a04c0e1ea13956e86b01c
Connecting to: mongodb://@192.168.1.210:27017/?replicaSet=example-mongodb&appName=mongosh+2.3.2
MongoNetworkError: getaddrinfo ENOTFOUND example-mongodb-0.example-mongodb-svc.mongodb.svc.cluster.local
Press any key to exit:

Someone can hellp me please and explain what is it necessary to do to access to the database from the external?

thanks
Gabriele

The Problem, I think, is that inside the cluser, kubernetes update the dns with the right order to land on the new primary, but the client is not able to see the new right order.
How is it possible to do this?
Below the error I receive and the first server is the new primary.
But my client is not able to see the kubernetes dns and the only ip that i’m able to see is the ip address of the control plane.

SERVER [example-mongodb-2.example-mongodb-svc.mongodb.svc.cluster.local:27017] (Type: UNKNOWN)
|/ Connection error (MongoSocketOpenException): Exception opening socket
|
___/ Unknown host: example-mongodb-2.example-mongodb-svc.mongodb.svc.cluster.local

SERVER [example-mongodb-0.example-mongodb-svc.mongodb.svc.cluster.local:27017] (Type: UNKNOWN)
|/ Connection error (MongoSocketOpenException): Exception opening socket
|
___/ Unknown host: example-mongodb-0.example-mongodb-svc.mongodb.svc.cluster.local

SERVER [example-mongodb-1.example-mongodb-svc.mongodb.svc.cluster.local:27017] (Type: UNKNOWN)
|/ Connection error (MongoSocketOpenException): Exception opening socket
|
___/ Unknown host: example-mongodb-1.example-mongodb-svc.mongodb.svc.cluster.local

Today the primary database switched but from the inside of the cluster everything is ok, i’m able to connect to the new primary but with the configuration i did to connect from outside the cluster it dowsn’t work. So it is not clear to me what to do to configure in tehe right way the kubernetes service to permit to follow the primary from outside the cluster.
Many thanks
Gabriele