2
votes

I am running 3 nodes in Kubernetes cluster. Each node has the same Pod myApp. I create a service using type NodePort so that all 3 Node is accessible from external. The service yaml looks like below

apiVersion: v1
kind: Service
metadata:
  name: myService
  labels:
    app: myApp
spec:
  selector:
    app: myApp
  type: NodePort

Suppose the Node IP + port of the 3 nodes are:
1. 192.168.18.1:30010
2. 192.168.18.2:30010
3. 192.168.18.3:30010

My questions are:
1. If all the requests comes to the single node with IP (192.168.18.1:30010), will the service load balancing the requests to Pod in other Nodes, or just the target node (IP 192.168.18.1:30010)?

2. If the answer to Question 1 is yes, which mean service can load balancing request. Then do we still need any load balancer.

Thanks

1

1 Answers

3
votes
  1. Yes load balancing will be provided by kube-proxy. If you look at the endpoints by describing a service you will find that IPs of pods backed by the service are listed there. So when request comes to the any nodes IP and NodePort it will be load balanced by kube-proxy between those pods. The way it works is request comes to one of the Node IP and port and then it goes to the cluster IP and then it gets load balanced to any of the pods behind the clusterIP.

  2. load balancing by kube proxy happens at TCP layer via IP table rules. Loadbalancer provides load balancing at L7 layer(HTTP) and advanced routing rules based on HTTP header etc. So if you need that then you need use Loadbalancer. Another disadvantage of using nodeport is that if Node IP changes then client needs to be aware of that which can be avoided by using Loadbalancer which generally provides a DNS.

enter image description here