作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在尝试将容器化的应用程序部署到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 }, ] }
最佳答案
就像@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/
我有一个流 randStream,它每半秒发出一次随机值,还有一个 boolStream,它将值从 randStream 转换为 bool 值。 let randStream = Kefir.from
我是一名优秀的程序员,十分优秀!