two Loadbalancing in kubernetes

4/6/2019

As I can see in below diagram I figure out in kubernetes we have two loadbalancer. One of them loadbalance between nodes and one of them loadbalance between pods.

If I use them both I have two loadbalancer.

Imagine some user want to connect to 10.32.0.5 the kubernetes send its request to node1(10.0.0.1) and after that send the request to pod (10.32.0.5) in nod3(10.0.0.3) but it is unuseful because the best route is to send request nod3(10.0.0.3) directly.

Why the NodePort is insufficient for load-balancing?

Why the NodePort is not LoadBalancer?(it LoadBalance between pods in different node but why we need another load balancer?)

note: I know that if I use NodePort and the node goes down it creates problem but I can say that I can use keepalived for it. The question is

why we need to loadbalance between nodes? keepalived attract all request to one IP. Why we have two loadbalancer?enter image description here

-- yasin lachini
kubernetes

1 Answer

4/7/2019

Wether you have two load-balancers depends on your setup.

In your example you have 3 nginx pods and 1 nginx service to access the pods. The service builds an abstraction layer, so you don't have to know how many pods there are and what IP addresses they have. You just have to talk to the service and it will loadbalance to one of the pods (docs).

It now depends on your setup how you access the service:

  • you might want to publish the service via NodePort. Then you can directly access the service on a node.
  • you might also publish it via LoadBalancer. This gives you another level of abstraction and the caller needs to know less about the actual setup of your cluster.

See docs for details.

-- Dirk
Source: StackOverflow