mongodb / mongodb-kubernetes-operator

MongoDB Community Kubernetes Operator
Other
1.22k stars 500 forks source link

Got "getaddrinfo ENOTFOUND mongodb replica set." error message. #946

Closed mike0355 closed 2 years ago

mike0355 commented 2 years ago

Hi , I'm a new on use Mongodb. When I deploy the mongodb operator on K8s from this github community,and I want to use local mongodb compass to connect this mongodb server . When I try to connect the mongodb server I got "getaddrinfo ENOTFOUND mongodb replica set." error massage. image

When I finished to deploy mongodb, I use port-forward command to port-forward this service ,and see this message on my browser. image image And here is my service... image

And here is my secret info. image

I follow this github to install and deploy mongodb, so I think my setting is correct. But I don't know why I get this problem.

priyolahiri commented 2 years ago

Please take a look at the external connectivity docs here.

sudobhat commented 2 years ago

Try selecting the Direct connection in the General tab - and turn off TLS if you have not configured it in TLS/SSL tab

BryanDollery commented 2 years ago

I have the same problem when using port-forward.

image

I have read the document referenced y priyolahiri, but it isn't related to this problem at all.

Does anyone have any clue as to how this is meant to work? I migrated to the community operator from the bitnami helm chart, but this approach works fine with that helm chart and doesn't seem to work at all with this operator mediated deployment.

AniketKariya commented 2 years ago

facing the same issue, any updates?

update: Authentication mechanism in my case was set to SCRAM-SHA-1. I set it to Default and it worked fine. I deployed mongodb using the community operator and exposed service using port forward.

also, check the direct connection checkbox

mike0355 commented 2 years ago

Hi , when I face this problem, I select the "Direct connect" this option and I solved this problem. image

mike0355 commented 2 years ago

And one thing need to notice , only primary MongoDB pod can provide read data and write data function. Secondary MongoDB pods only save the data.

mike0355 commented 2 years ago

For BryanDollery's problem Is your port-forward port is 8000:27017? that means container environment port forward to the local side's 8000 port. So you need to select the 8000 port and select the "Direct connect".

AniketKariya commented 2 years ago

however, the solution creates another issue, as stating from https://www.mongodb.com/docs/compass/current/connect/general-connection/

onnection and connect to a secondary member of a replica set, your write operations fail because it is not the primary member.

this solution, as temporary to test whether the connection succeeds is fine, but I am not sure if this would connect from backend (for instance node) as there'd be no option to connect directly, or even if there is, it would connect to secondary node and would deny any write operations. please look into this.

mike0355 commented 2 years ago

One method can observed which one pod is primary member. It is enter to the mongodb pods container environment to check . Use" kubectl exec -it -c mongod /bin/bash " cammand to enter to the mongoDB container environment and you will see which node you entered , and you can use mongoDB cammand to control your mongoDB databases in the container environment . Also you can use VIM editor to change the number of parameter "member". If only one MongoDB pod deploy on K8s environment,and that MongoDB pod must be primary node. And after you can edit again , change the number of parameter "member" to another number, when you port-forward again, I think you can connect to the primary node mongoDB pod by default setting.

github-actions[bot] commented 2 years ago

This issue is being marked stale because it has been open for 60 days with no activity. Please comment if this issue is still affecting you. If there is no change, this issue will be closed in 30 days.

github-actions[bot] commented 2 years ago

This issue was closed because it became stale and did not receive further updates. If the issue is still affecting you, please re-open it, or file a fresh Issue with updated information.

leozvoy commented 1 year ago

Try selecting the Direct connection in the General tab - and turn off TLS if you have not configured it in TLS/SSL tab

You save my day(night)!

bnhNhan commented 1 year ago
cateyelow commented 6 months ago

the issue is cause because of /etc/hosts in your client which running MongoDB Compass. you have to sync /etc/hosts to find your replicaset. maybe if you use kubernetes, maybe you have to use NAT or port-forwarding

[Example] suggest you set /etc/hosts like that

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

192.168.0.X mongo0.replset.member
192.168.0.X mongo1.replset.member
192.168.0.X mongo2.replset.member

then you have to sync the /etc/hosts with public ip in external if you want to activate replica

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

121.X.X.X mongo0.replset.member
121.X.X.X mongo1.replset.member
121.X.X.X mongo2.replset.member

then try connect in external env

mongodb://id:password@[your_host]:27017,[your_host]27018,[your_host]:27019/?authMechanism=SCRAM-SHA-1&replicaSet=rs0&readPreference=secondaryPreferred

Additionally, it is general ways that changing your member names with domain and port-forwarding in production