gpt4 book ai didi

docker - GKE无法到达MongoDB Atlas

转载 作者:行者123 更新时间:2023-12-01 20:24:47 33 4
gpt4 key购买 nike

我在尝试将容器化的应用程序部署到GKE时遇到问题。它无法访问我的MongoDB Atlas集群。在本地运行Docker容器不会产生任何问题,并且运行良好。我绝不是Docker或Kubernetes的专家,但我认为这与DNS名称解析有关。

我已经按照本教程Deploying a containerized web application进行了操作,另外还添加了LoadBalancer的EXTERNAL-IP到MongoDB Atlas控制台的“网络访问” IP白名单中,并使用端口映射443-> 8443,因为我正在使用HTTPS。

仅在失败前记录我的应用程序能够产生的日志:

(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 }, ] }

如果对此有一个简单的解决方法,那将是首选,因为该应用程序仍处于开发阶段,因此我只需要一个使用上述技术的基本可用的应用程序。

完整的工作流程:

Android应用程序->在Docker上运行的Golang API-> MongoDB Atlas

谢谢

最佳答案

就像@Marc那样,您的流量是通过工作节点的EXTERNAL-IP发出的,而不是负载平衡器发出的。
要查找EXTERNAL-IP IP的节点,请使用:

kubectl get nodes -owide
更准确地说,仅输出IP使用(取自 kubectl Cheat Sheet):
kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'
接下来将这些IP列入白名单,您应该会很好,但是请记住,在Kubernetes升级或集群扩展之后,这些IP可能会更改,因此我建议使用 Cloud NAT始终为您的传出流量使用相同的IP。

关于docker - GKE无法到达MongoDB Atlas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62104559/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com