我在尝试将容器化应用部署到 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
德玛西亚99
相关分类