简体   繁体   English

kubernetes服务如何确定路由到哪个后端Pod

[英]how does kubernetes service decide which backend pod to route to

I have a Kubernetes Service that selects by doing: 我有一个Kubernetes服务可以通过以下方式进行选择:

spec: 
  selector: 
    backend: nlp-server

If there are multiple Pods which match the selector, which Pod does the Service route a request to? 如果有多个Pods匹配选择哪个,该Pod是否Service路由的请求?

I am using the default ClusterIP setup. 我正在使用默认的ClusterIP设置。 Search for "ClusterIP: Exposes the service on a cluster-internal IP. Choosing this value makes the service only reachable from within the cluster. This is the default ServiceType." 搜索“ ClusterIP:在群集内部IP上公开服务。选择此值将使该服务仅可从群集内部访问。这是默认的ServiceType。” in the docs 文档中

If I want the Service to route to a Pod that makes sense (having lesser load), 如果我希望服务路由到有意义的Pod(负载较小),
is the internal load-balancer what I need? 我需要内部负载均衡器吗?

In a nutshell, no you don't need the internal load-balancer you linked to. 简而言之,不,您不需要链接到的内部负载均衡器。 The Service resource is indeed a load-balancer. Service资源确实一个负载均衡。 Depending on the proxy mode it could be round-robin or random. 根据代理模式的不同,它可以是轮询或随机的。 If you're going with the default (iptables-based proxy) it would be a random pod selected every time you hit the virtual IP of the service. 如果使用默认的(基于iptables的代理),则每次您点击服务的虚拟IP时都会选择一个随机Pod

Note: you could use the internal load-balancer type, typically in a cloud environment such as GKE , for example to cut down on costs when all you need is cluster-internal connectivity, however they are (as far as I know) usually L4 load-balancers. 注意:您可以使用内部负载平衡器类型,通常在云环境( 例如GKE)中使用 ,例如,当您需要的是集群内部连接时,可以降低成本,但是据我所知,它们通常是L4负载均衡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM