我正在尝试将在 GCP Kubernetes 引擎集群上运行的 Java 应用程序与 Mongo Atlas 集群(M20)连接起来。之前,当我没有打开 VPC 对等互连并且我使用的是常规连接字符串时,它运行良好。但我现在正在尝试使用 VPC 对等互连,并default
在我的 GCP 项目中使用 VPC 网络。我按照https://docs.atlas.mongodb.com/security-vpc-peering/中的步骤操作。我选择了192.168.0.0/18的Atlas CIDR(b/c“The Atlas CIDR block must be at least a /18”),将GCP项目和Atlas集群链接后,将10.128.0.0/9加入IP白名单对于 Atlas 集群(b/c 它说这是 GCP 项目中 auto 的默认范围)。
我实际上可以通过 Mongo shell via mongo "mongodb+srv://<cluster_name>-pri.crum0.gcp.mongodb.net/itls"
,从我的 GCP 项目中的其他一些 VM 进行连接。但是在我的 GCP 集群中的 pod 上运行的应用程序无法连接。我在 Java 应用程序中看到的确切错误是
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=<cluster_name>-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=<cluster_name>-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=<cluster_new>-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}}]
可能的问题:
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?
任何帮助,将不胜感激。