在群集外使用StatefulSets将Kubernetes上的MongoDB公开 [英] Expose MongoDB on Kubernetes with StatefulSets outside cluster

查看:844
本文介绍了在群集外使用StatefulSets将Kubernetes上的MongoDB公开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循以下链接中的指南:
http://blog.kubernetes.io/2017/01/running-mongodb-on-kubernetes-with-statefulsets.html



<使用StatefulSets在Kubernetes上设置mongo数据库副本集。到目前为止这么好,但我如何在群集外部公开该静态主机名,以便我可以从Google实例访问它们?



如果我使用节点的IP,它可以正常工作,但随时可以更改(在POD失败并使用不同的IP等重新启动时)

解决方案

它看起来像答案存在于StatefulSet Basics文档部分使用稳定的网络身份


Pods的序号,主机名,SRV记录和A记录名称的
没有更改,但与Pod相关的IP地址可能已更改
。在本教程使用的集群中,他们有。这就是为什么
不需要配置其他应用程序来连接到基于IP地址的StatefulSet中的Pod



如果您需要查找并连接到
StatefulSet的活动成员,您应该查询无头服务
(nginx.default.svc.cluster.local)的CNAME 即可。与
CNAME关联的SRV记录将只包含StatefulSet中正在运行
和Ready的Pod。



如果您的应用程序已经实现了连接测试
活跃性和准备性的逻辑,您可以使用Pods的 (web-> 0.nginx.default.svc.cluster.local,web-1 .nginx.default.svc.cluster.local)
,因为它们是稳定的,您的
应用程序将能够在它们发现Pod时的地址
转换为跑步和准备。



I followed the guide in the following link: http://blog.kubernetes.io/2017/01/running-mongodb-on-kubernetes-with-statefulsets.html

and set up a mongo DB replica set on Kubernetes with StatefulSets. So far so good, but how do I expose that static hostnames outside the cluster so that I can access them from a Google instance for example?

If I use the IPs of the nodes it will work fine but those can change anytime (upon pod failure and restart with a different IP etc.)...

Thanks in advance!

解决方案

It looks like the answer is present in the StatefulSet Basics documentation section 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.

这篇关于在群集外使用StatefulSets将Kubernetes上的MongoDB公开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆