GKE无法访问MongoDB Atlas [英] GKE not able to reach MongoDB Atlas
本文介绍了GKE无法访问MongoDB Atlas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试将我的容器化应用程序部署到GKE时遇到问题。它无法访问我的MongoDB Atlas集群。在本地运行Docker容器不会产生任何问题,并且运行得很好。我绝对不是Docker或Kubernetes方面的专家,但我认为这与DNS名称解析有关。
我遵循了本教程-Deploying a containerized web application,因为我使用的是HTTPS,所以添加了一个LoadBalancer的外部IP到MongoDB Atlas控制台中我的‘Network Access’IP白名单中,并使用了端口映射443->8443。
仅我的应用程序在失败前能够生成的日志:
(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 App->Docker上运行的Golang API->MongoDB Atlas
谢谢
推荐答案
与@marc point完全一样,您的流量通过工作节点的外部IP流出,而不是通过负载均衡器。
要查找节点外部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。
这篇关于GKE无法访问MongoDB Atlas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文