mongodb - 在集群外使用 StatefulSets 在 Kubernetes 上公开 MongoDB

标签 mongodb kubernetes google-cloud-platform

我按照以下链接中的指南进行操作: 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/

相关文章:

node.js - 如何使用 Mongoose/MongoDB 查找集合的子文档并更新它?

python - 我将如何使用 python 遍历 Google Cloud Storage 上子目录中的所有文件名?

google-compute-engine - 仪表板和 VM 中的 Google Compute Engine CPU 使用差异

kubernetes - AWS EKS 集群的 "cluster creator"用户如何映射到 "system:masters"RBAC 组?

docker - SVN代码存储库中Kubernetes资源YAML文件的可行性

google-cloud-platform - wercker 中 GCR 的 docker-push 失败

mysql - Elasticsearch + 还有什么?

mongodb - mongodb 的 'updateMany' 函数是否已弃用?

node.js - 在 Mongoose 中填写所有必填字段

elasticsearch - 具有基本身份验证的Elasticsearch Helm chart