Which algorithm Kubernetes uses to nevigate traffics in replicaset/deployment

4/7/2019

I was asked about it, and I couldn't find info about it online - Which algorithm Kubernetes uses to nevigate traffics in replicaset or deployment (I guess that they the same) for pods?

Lets say, I have replica of 5 pods in my Kubernetes cluster, defined in replicaset. How does the cluster pick which pod to go to, in new request? Is it uses round-robin? I couldn't find info about it.

-- Yagel
kubernetes
kubernetes-deployment
replicaset

1 Answer

4/8/2019

The algorithm applied to determine which pod will process the request depends on kube-proxy mode that is running.

  • In 1.0, the proxy works in mode called userspace and default algorithm is round robin.

  • In 1.2 mode iptables proxy was added, but still round robin is used due to iptables limitations.

  • In 1.8.0-beta, IP Virtual Server (IPVS) was introduced, it allow much more algorithms options, like:

    • RoundRobin;
    • WeightedRoundRobin;
    • LeastConnection;
    • WeightedLeastConnection;
    • LocalityBasedLeastConnection;
    • LocalityBasedLeastConnectionWithReplication;
    • SourceHashing;
    • DestinationHashing;
    • ShortestExpectedDelay;
    • NeverQueue.

References:

https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies https://sookocheff.com/post/kubernetes/understanding-kubernetes-networking-model/

-- Luis Brito
Source: StackOverflow