title: Cannot connect to Mongo Atlas using VPC peering from GCP cluster
body: <p>I am trying to connect a Java app running on a GCP Kubernetes engine cluster, with a Mongo Atlas cluster (M20). Before, it worked fine, when I didn't have VPC Peering turned on and I was using the regular connection string. But I am trying to use VPC Peering now, with the <code>default</code> VPC network in my GCP project. I followed the steps in <a href="https://docs.atlas.mongodb.com/security-vpc-peering/" rel="nofollow noreferrer">https://docs.atlas.mongodb.com/security-vpc-peering/</a>. I chose Atlas CIDR of 192.168.0.0/18 (b/c "The Atlas CIDR block must be at least a /18"), and after linking the GCP project and the Atlas cluster, added 10.128.0.0/9 to the IP whitelist for the Atlas cluster (b/c it says that is the default range for auto in GCP projects).</p>
  
  <p>I am actually able to connect via Mongo shell via <code>mongo "mongodb+srv://&lt;cluster_name&gt;-pri.crum0.gcp.mongodb.net/itls"</code>, from some other VM in my GCP project. But the app running on a pod in my GCP cluster is unable to connect. The exact error that I am seeing in the Java app is</p>
  
  <pre><code>Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@a07fbd8. Client view of cluster state is {type=REPLICA_SET, servers=[{address=&lt;cluster_name&gt;-shard-00-00-pri.crum0.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=&lt;cluster_name&gt;-shard-00-01-pri.crum0.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=&lt;cluster_new&gt;-shard-00-02-pri.crum0.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]
  </code></pre>
  
  <p>Possible issues:</p>
  
  <pre><code>1) is it possible to connect from a GCP cluster at all (or perhaps, why is this cluster somehow not part of default VPC network)?
  2) is there something wrong in the Atlas CIDR range or my IP whitelist range?
  </code></pre>
  
  <p>Any help would be appreciated.</p>