skip to Main Content

issue: My application in GKE is not able to connect with mongo Atlas over VPC peering , however if I run mongosh from a pod in GkE cluster manually using mongodb+srv://cluster0-pri.mongodb.net/test --apiVersion 1 --username user --password pass it works well.

I did a little more investigation in my case and figured out something un usual. In application properties I am using
uri: mongodb+srv://user:[email protected]/test URI and because of this it is taking a public route and not going through vpc peering, I test and I am getting same timeout while I try to ssh from a pod to mongo cluster after I remove 0.0.0.0/0 from ip whitelist in atlas.
is there a Better way of making application communicate with mongo in GKE/GCP. or a different way of using URI like below

mongodb+srv://cluster0.mongodb.net/test?apiVersion=1&username=<user>&password=<pass>
when I tried this command it say that apiversion is not supported and if I run the same command like below it works fine
mongodb+srv://cluster0.mongodb.net/test --apiVersion 1 --username user --password pass

2

Answers


  1. Chosen as BEST ANSWER

    The fix was to add primary to the Uri that we are using, when you add -pri it will allow the source to resolve at private ip

    uri: mongodb+srv://user:[email protected]/test


  2. You can try using cloud NAT instead of VPC peering. From the link shared, you can assign or reserve a static IP address to the router that will be used once you create a cloud NAT.

    Since the router’s IP address is static (permanent) it’s safe to use and whitelist the IP address to MongoDB Atlas under Network Access -> IP Access list instead of using 0.0.0.0/0. Its normal that you have a timeout error message once you remove the whitelist, because it only allows client connection once IP address is whitelisted, you can see this information in this link

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search