how does kubernetes service decide which backend pod to route to

9/11/2018

I have a Kubernetes Service that selects by doing:

spec: 
  selector: 
    backend: nlp-server

If there are multiple Pods which match the selector, which Pod does the Service route a request to?

I am using the default ClusterIP setup. 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." in the docs

If I want the Service to route to a Pod that makes sense (having lesser load),
is the internal load-balancer what I need?

-- cryanbhu
kubernetes
kubernetes-service

1 Answer

9/11/2018

In a nutshell, no you don't need the internal load-balancer you linked to. The Service resource is indeed a load-balancer. 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.

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.

-- Michael Hausenblas
Source: StackOverflow