【发布时间】:2020-06-09 06:23:43
【问题描述】:
我正在尝试将在 GCP Kubernetes 引擎集群上运行的 Java 应用程序与 Mongo Atlas 集群 (M20) 连接起来。以前,当我没有打开 VPC 对等互连并且我使用的是常规连接字符串时,它运行良好。但我现在正在尝试使用 VPC 对等互连,在我的 GCP 项目中使用 default 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 "mongodb+srv://<cluster_name>-pri.crum0.gcp.mongodb.net/itls" 从我的 GCP 项目中的其他一些虚拟机通过 Mongo shell 进行连接。但是在我的 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?
任何帮助将不胜感激。
【问题讨论】:
-
您能否在正在运行的 pod 中进行基本检查:找出您的 Java 应用程序 pod 名称
kubectl get pods,然后找到kubectl exec java_pod_name ping <cluster_name>-pri.crum0.gcp.mongodb.net? -
关于使用 mongo shell 访问的其他 VM。它使用的是什么IP?另外,你能运行一个 linux pod,比如 ubuntu,登录进去,下载 mongo shell 并检查你是否可以从那里连接?这样我们就可以检查它是java应用还是集群本身。
-
如果您需要该命令,则:
kubectl run -it --rm --generator=run-pod/v1 ubuntu --image=ubuntu -- /bin/bash会将您登录到 pod 内的 shell,以便您可以apt-get install并运行 ping 和 mongo shell 命令。 -
在 VPC 网络对等设置中查看导出的路由,并在全面白名单生效时检查哪个 IP 地址连接到 MongoDB。更多详情developer.mongodb.com/community/forums/t/…
标签: mongodb google-cloud-platform mongodb-atlas vpc google-vpc