LoadBalancer - Kubernetes or Nginx Or Both

10/7/2019

Nginx by default support 'Round Robin' load balancing and if i have kubernetes service type as 'LoadBalancer' (i think this is network-LB of the service provider? like this) wouldn't that will make two load balancers in the stack (in theory)?

Assuming, i have single web-app behind nginx (web-server) so i guess in this case no nginx-LB will happen. But when it scales to multiple web-app behind nginx it would start load-balancing.

What is the best topology, having all the web-app utilizing network load-balancer (hardware) or multiple web-apps behind single nginx?

1) Single nginx for multiple web-app(s)

                          |=> web-app
network-LB <==> nginx-LB <==> web-app
                          |=> web-app

2) Let network LB do the balancing and nginx for each web-app as web-server?

                nginx-LB <==> web-app
network-LB <==> nginx-LB <==> web-app
                nginx-LB <==> web-app
-- Milind Deore
kubernetes
nginx

1 Answer

10/7/2019

So the general flow for this would be to incorporate an Nginx ingress instead of Nginx as a LB, as the Nginx ingress controller is optimized for this kind of routing and supports autoscaling so you don't need to handle anything underload, the idea being.

                                               |=> web-app
network-LB <==> nginx-controller (one or more) <==> web-app
                                               |=> web-app

However your nginx conroller does a bit of magic where it watches the endpoints of your webapps and on change updates the config so there is one less hop (more optimal than normal routing that would need to do an IP lookup before hand). You can read more about nginx ingress here

-- Spazzy757
Source: StackOverflow