Home > Enterprise >  Why is there a load balancer in ingress controller?
Why is there a load balancer in ingress controller?

Time:08-01

While reading about ingress and ingress controller in k8s, it is documented that there is a load balancer in the ingress controller.

From my understanding, The ingress controller only accepts external requests and forwards them to the target service (the load balancing between the pods actually happens here) so, there is no need to balance the load at the level of the ingress controller!

Can anyone clarify the correct scenario?

CodePudding user response:

You have the right mental model of the implementation of ingress, though it is not what is actually happening:

Ingress -> Service -> 1..n Endpoints (Pods)

In practice this can lead to problems, though: If you want to influence the actual load balancing and use additional information (like a cookie for sticky sessions) the Ingress must make the decision itself and can not delegate this to the service.

Therefore usually an Ingress queries the endpoints of a service and handles http request balancing itself.

You can observe this actually: Create a small app that echos the hostname (pod name), for example using PHP and a webserver that allows http keepalive. When exposing through LoadBalancer or NodePort you will notice that reloading in the browser does not change the pod per request. cURL will show different pod names per request. This is due to the re-use of the TCP connection so the Service does not re-balance.

If you use an Ingress you will notice that the requests are load balanced across the Pods.

  • Related