什么是无头服务,它能完成/完成什么工作,合法的用例有哪些? [英] What exactly is a headless service, what does it do/accomplish, and what are some legitimate use cases for it?

查看:86
本文介绍了什么是无头服务,它能完成/完成什么工作,合法的用例有哪些?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一些用Kubernetes编写的书以及文档中有关无头服务的页面的几段内容.但是我仍然不确定它的真正作用以及为什么有人会使用它.是否有人对它有很好的了解,它能完成什么以及为什么有人会使用它?

I've read a couple of passages from some books written on Kubernetes as well as the page on headless services in the docs. But I'm still unsure what it really actually does and why someone would use it. Does anyone have a good understanding of it, what it accomplishes, and why someone would use it?

推荐答案

嗯,我认为您需要一些理论.整个互联网上有很多解释(包括官方文档),但是我认为Marco Luksa做到了最好:

Well, I think you need some theory. There are many explanations (including the official docs) across the whole internet, but I think Marco Luksa did it the best:

与服务的每个连接都转发给随机选择的一个 后备箱.但是,如果客户端需要连接所有这些客户端,该怎么办? 豆荚?如果后备箱本身需要连接到所有人,该怎么办 其他的支撑豆荚.显然不是通过服务进行连接 做到这一点的方式.什么是?

Each connection to the service is forwarded to one randomly selected backing pod. But what if the client needs to connect to all of those pods? What if the backing pods themselves need to each connect to all the other backing pods. Connecting through the service clearly isn’t the way to do this. What is?

要使客户端连接到所有Pod,需要确定IP 每个豆荚的一种选择是让客户致电 Kubernetes API服务器并获取Pod列表及其IP地址 通过API调用,但是因为您应该始终努力保持自己的 与Kubernetes无关的应用,使用API​​服务器并不理想

For a client to connect to all pods, it needs to figure out the the IP of each individual pod. One option is to have the client call the Kubernetes API server and get the list of pods and their IP addresses through an API call, but because you should always strive to keep your apps Kubernetes-agnostic, using the API server isn’t ideal

幸运的是,Kubernetes允许客户端通过DNS发现pod IP. 查找.通常,当您对服务执行DNS查找时,DNS 服务器返回一个IP(服务的群集IP).但是如果你告诉 Kubernetes不需要服务的群集IP(您可以执行此操作 通过在服务规范中将clusterIP字段设置为无", DNS服务器将返回容器IP而不是单个服务 IP. DNS服务器不会返回单个DNS A记录,而是返回 返回该服务的多个A记录,每个记录指向IP的IP 当时支持该服务的个人广告连播.客户可以 因此,请做一个简单的DNS A记录查找,并获取所有IP的IP. 服务中包含的广告连播.然后客户可以使用 连接到一个,多个或全部信息.

Luckily, Kubernetes allows clients to discover pod IPs through DNS lookups. Usually, when you perform a DNS lookup for a service, the DNS server returns a single IP — the service’s cluster IP. But if you tell Kubernetes you don’t need a cluster IP for your service (you do this by setting the clusterIP field to None in the service specification ), the DNS server will return the pod IPs instead of the single service IP. Instead of returning a single DNS A record, the DNS server will return multiple A records for the service, each pointing to the IP of an individual pod backing the service at that moment. Clients can therefore do a simple DNS A record lookup and get the IPs of all the pods that are part of the service. The client can then use that information to connect to one, many, or all of them.

将服务规范中的clusterIP字段设置为无", 服务无头,因为Kubernetes不会通过以下方式为其分配群集IP 哪些客户端可以连接到支持它的Pod.

Setting the clusterIP field in a service spec to None makes the service headless, as Kubernetes won’t assign it a cluster IP through which clients could connect to the pods backing it.

Marco Luksa的"Kubernetes在行动"

"Kubernetes in Action" by Marco Luksa

这篇关于什么是无头服务,它能完成/完成什么工作,合法的用例有哪些?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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