我在尝试将容器化应用部署到 GKE 时遇到问题。它无法访问我的 MongoDB Atlas 集群。在本地运行 Docker 容器不会产生任何问题并且运行良好。我绝不是 Docker 或 Kubernetes 方面的专家,但我认为这与 DNS 名称解析有关。我已遵循本教程-部署容器化 Web 应用程序,并在 MongoDB Atlas 控制台中将 LoadBalancer 的 EXTERNAL-IP 添加到我的“网络访问”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
1 回答

德玛西亚99
TA贡献1770条经验 获得超3个赞
您的流量是通过工作节点的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。
- 1 回答
- 0 关注
- 136 浏览
添加回答
举报
0/150
提交
取消