简体   繁体   English

GKE 无法到达 MongoDB Atlas

[英]GKE not able to reach MongoDB Atlas

I have an issue with trying to deploy my containerized app to GKE.我在尝试将容器化应用部署到 GKE 时遇到问题。 It is not able to reach my MongoDB Atlas cluster.它无法访问我的 MongoDB Atlas 集群。 Running the Docker container locally creates no issues and works perfectly.在本地运行 Docker 容器不会产生任何问题并且运行良好。 I am by no means an expert in Docker or Kubernetes, but I am assuming it is something to do with the DNS name resolution.我绝不是 Docker 或 Kubernetes 方面的专家,但我假设这与 DNS 名称解析有关。

I have followed this tutorial - Deploying a containerized web application , with an addition of adding an EXTERNAL-IP of the LoadBalancer to my 'Network Access' IP Whitelist in the MongoDB Atlas console and using port mapping 443 -> 8443 since I am using HTTPS. I have followed this tutorial - Deploying a containerized web application , with an addition of adding an EXTERNAL-IP of the LoadBalancer to my 'Network Access' IP Whitelist in the MongoDB Atlas console and using port mapping 443 -> 8443 since I am using HTTPS .

Only logs that my app is able to produce before failing:仅记录我的应用程序在失败之前能够生成的日志:

(mongodb): 2020/05/30 15:07:39 logger.go:96: 2020-05-30T15:07:39Z 
[error] Failed to connect to mongodb. Check if mongo is running...
(mongodb): 2020/05/30 15:07:39 logger.go:132: 2020-05-30T15:07:39Z 
[fatal] server selection error: server selection timeout, current 
topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: biomas- 
cluster-shard-<removed>.azure.mongodb.net:27017, Type: Unknown, 
State: Connected, Average RTT: 0, Last error: connection() : 
connection(biomas-cluster-shard-<removed>.azure.mongodb.net:27017[-180]) incomplete read of message 
header: EOF }, { Addr: biomas-cluster-shard-<removed>.azure.mongodb.net:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : connection(biomas-cluster-shard-<removed>.azure.mongodb.net:27017[-181]) incomplete read of message header: EOF }, { Addr: biomas-cluster-shard-<removed>.azure.mongodb.net:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : connection(biomas-cluster-shard-<removed>.azure.mongodb.net:27017[-179]) incomplete read of message header: EOF }, ] }

If there is a simple workaround with to this, that would be preferred since the app is in the development stage still, so I just need a basically working application using the said technologies.如果有一个简单的解决方法,那将是首选,因为该应用程序仍处于开发阶段,所以我只需要一个使用上述技术的基本工作应用程序。

The full workflow:完整的工作流程:

Android App -> Golang API running on Docker -> MongoDB Atlas Android App -> Golang API 运行在 Docker -> Z206E3718AF092FD1D12F80CAE771AtlasCC

Thanks谢谢

Exactly as @Marc point, your traffic got out with EXTERNAL-IP of your worker nodes, not your load balancer.正如@Marc 所说,您的流量是通过工作节点的EXTERNAL-IP 流出的,而不是您的负载均衡器。

To find nodes EXTERNAL-IP IPs use:要查找节点 EXTERNAL-IP IP,请使用:

kubectl get nodes -owide

To be more precise and output only IPs use (taken from kubectl Cheat Sheet ):更准确地说,output 仅使用 IP(取自kubectl 备忘单):

kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'

Next whitelist those IPs and you should be good, but keep in mind that after Kubernetes upgrade or cluster scaling the IPs might change, so I recommend using Cloud NAT to always have the same IP for your outgoing traffic.接下来将这些 IP 列入白名单,您应该会很好,但请记住,在 Kubernetes 升级或集群扩展之后,IP 可能会发生变化,因此我建议使用Cloud NAT始终为您的传出流量使用相同的 IP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM