VPC peering MongoDB Atlas with GCP Kubernetes engin

472 views Asked by At

I followed https://docs.atlas.mongodb.com/security-vpc-peering/ and created VPC peering and checked activated both side (GCP and Atlas). and My GCP VPC-native is enabled.

mongodb cidr 192.168.0.0/16

GCP pod ip range 10.4.0.0/16

I added 10.4.0.0/16 into Atlas white list and try to connect via private connection string in one of pods

mongo "mongodb+srv://id:[email protected]/dbname"

but it returns error

*** You have failed to connect to a MongoDB Atlas cluster. Please ensure that your IP allowlist allows connections from your network.
Error: Could not find host matching read preference { mode: "nearest" }

nslookup in pod to mongodb cluster shows

Server:         10.4.128.10
Address:        10.4.128.10#53

Name:   dbname-pri.some.mongodb.net
Address: 192.168.254.213

I just added whitelist 0.0.0.0/0 into Atlas. but it returns same errors. it may definitely not the problem of whitelist.

Should I setup firewall or something else?

1

There are 1 answers

2
Lion.k On BEST ANSWER

I found an answer!

I hope this help to people suffering with same problems with me.

Solution

The mongodb Atlas cluster is created AWS based. 
this AWS based cluster cannot be connected with GCP via VPC peering.

If you want to connect to GCP, you should make GCP based mongodb cluster.

The key issue was that. and some other points are,

  1. should use private connection string with "-pri"
  2. GCP VPC-native should be enabled
  3. use CIDR GCP pod ip range(you can show this GCP kubernetes main page)

this would be help.