Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes Service not distributing the traffic evenly among pods

Tags:

I am using Kubernetes v1.20.10 baremetal installation. It has one master node and 3 worker nodes. The application simply served HTTP requests.

I am scaling the deployment based on the (HPA) Horizontal Pod Autoscaler and I noticed that the load is not getting evenly across pods. Only the first pod is getting 95% of the load and the other Pod is getting very low load.

I tried the answer mentioned here but did not work : Kubernetes service does not distribute requests between pods

like image 811
Anthony Vinay Avatar asked Aug 27 '21 16:08

Anthony Vinay


People also ask

Do Kubernetes services load balance?

With Kubernetes you don't need to modify your application to use an unfamiliar service discovery mechanism. Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods, and can load-balance across them.

How does Kubernetes service select which pods to direct traffic to?

Kubernetes will automatically assign an IP address (“Cluster IP”) which will then be used by service proxies to route the traffic. The controller for the selector will consistently monitor for Pods matching the defined label. Some applications will require multiple ports to be exposed via the service.

How does Kubernetes load balancer between pods?

The load balancer tracks the availability of pods with the Kubernetes Endpoints API. When it receives a request for a specific Kubernetes service, the Kubernetes load balancer sorts in order or round robins the request among relevant Kubernetes pods for the service.

Does ClusterIP load balance?

The ClusterIP provides a load-balanced IP address. One or more pods that match a label selector can forward traffic to the IP address. The ClusterIP service must define one or more ports to listen on with target ports to forward TCP/UDP traffic to containers.


1 Answers

Based on the information provided I assume that you are using http-keepalive which is a persistent tcp connection. A kubernetes service distributes load for each (new) tcp connection. If you have persistent connections, only the additional connections will be distributed which is the effect that you observe.

Try: Disable http keepalive or set the maximum keepalive time to something like 15 seconds, maximum requests to 50.

like image 172
Thomas Avatar answered Oct 11 '22 19:10

Thomas