gpt4 book ai didi

kubernetes - 什么是 headless 服务,它做什么/完成什么,以及它的一些合法用例是什么?

转载 作者:行者123 更新时间:2023-12-02 23:40:05 25 4
gpt4 key购买 nike

我读过一些关于 Kubernetes 的书籍以及 page on headless services in the docs 中的一些段落。 。但我仍然不确定它的真正用途以及为什么有人会使用它。有人很好地理解它、它的功能以及为什么有人会使用它吗?

最佳答案

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

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?

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

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.

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 - 什么是 headless 服务,它做什么/完成什么,以及它的一些合法用例是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52707840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com