Golang driver get error when run mongodb on k8s

I have a mongodb run on k8s, single node, export connect string as “mongodb://squids:Dbmotion&1@10.10.40.152:35/”

when I connect it with golang driver, it report error like ‘2022/04/14 09:30:00 server selection error: context deadline exceeded, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: mongo-a9f01-replica0-0-0.mongo-a9f01-replica0-headless.qfusion-admin:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp: lookup mongo-a9f01-replica0-0-0.mongo-a9f01-replica0-headless.qfusion-admin on 192.168.65.5:53: no such host }, ] }’

the 192.168.65.5:53 is the dns server of k8s, and mongo-a9f01-replica0-0-0.mongo-a9f01-replica0-headless.qfusion-admin:27017 is the mongodb service provide in internal network in k8s, which can not access from my client. we can not deploy the application to k8s.

if I change connection uri to “mongodb://squids:Dbmotion&1@10.10.40.152:35/?directConnection=true”, I can access to mongodb without error, but if the performance slow down from 600MB/s to 100MB/s when insert to collections.

How to ensure that no errors are reported and performance is not degraded

I test it with c++ driver, it does not report error if not set ‘directConnection=true’

Does anyone have any suggestions to fix this: with directConnect=true the performance is poor; if not, the connection throws an error