我按照以下链接中的指南进行操作: http://blog.kubernetes.io/2017/01/running-mongodb-on-kubernetes-with-statefulsets.html
并使用 StatefulSets 在 Kubernetes 上设置一个 mongo DB 副本集。到目前为止一切都很好,但是我如何在集群外部公开这些静态主机名,以便我可以从谷歌实例访问它们?
如果我使用节点的 IP,它可以正常工作,但这些可以随时更改(在 pod 失败并使用不同的 IP 重新启动等时)...
提前致谢!
最佳答案
答案似乎出现在 StatefulSet Basics 文档部分 Using Stable Network Identities :
The Pods’ ordinals, hostnames, SRV records, and A record names have not changed, but the IP addresses associated with the Pods may have changed. In the cluster used for this tutorial, they have. This is why it is important not to configure other applications to connect to Pods in a StatefulSet by IP address.
If you need to find and connect to the active members of a StatefulSet, you should query the CNAME of the Headless Service
(nginx.default.svc.cluster.local)
. The SRV records associated with the CNAME will contain only the Pods in the StatefulSet that are Running and Ready.If your application already implements connection logic that tests for liveness and readiness, you can use the SRV records of the Pods
( web-> 0.nginx.default.svc.cluster.local, web-1.nginx.default.svc.cluster.local)
, as they are stable, and your application will be able to discover the Pods’ addresses when they transition to Running and Ready.
关于mongodb - 在集群外使用 StatefulSets 在 Kubernetes 上公开 MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41969626/