Search code examples
kuberneteskubernetes-ingressmetallbbare-metal-server

Is it double load-balancing when using MetalLB and a ClusterIP service?


I use MetalLB and Nginx-ingress controller to provide internet access to my apps. I see that in most configurations, the service is set to ClusterIP, as the ingress will send traffic there.

My question is: does this end up with double load balancing, that is, one from MetalLB to my ingress, and another from my ingress to the pods via ClusterIP?

If so, is this how it is supposed to be, or is there a better way?


Solution

  • Metallb doesn't receive and forward any traffic, so

    from MetalLB to my ingress

    doesn't really make sense. Metallb just configures kubernetes services with an external ip and tells your surrounding infrastructure where to find it. Still with your setup there will be double load-balancing:

    Traffic reaches your cluster and is load-balanced between your nginx pods. Nginx handles the request and forwards it to the application, which will result in a second load-balancing.

    But this makes total sense, because if you're using an ingress-controller, you don't want all incoming traffic to go through the same pod.

    Using an ingress-controller with metallb can be done and can improve stability while performing updates on you application, but it's not required.

    Metallb is a solution to implement kubernetes services of type LoadBalancer when there is no cloud provider to do that for you.

    So if you don't need layer 7 load-balancing mechanism you can instead of using a service of type ClusterIP with an ingress-controller just use a service of type LoadBalancer. Metallb will give that service an external ip from your pool and announce it to it's peers.

    In that case, when traffic reaches the cluster it will only be load-balanced once.