Kubernetes load balancing not working for multiple pods in same node

1/14/2020

Let me try and explain this as best as i could:

  1. Using only 1 node (single node clustering)
  2. 3 Pods (Pod A, Pod B, Pod C) of same application in this node. These are vendor application which are not restful application. They are java application. Application in these pod will open TCP listener port 8888. So Pod A, Pod B, Pod C each has port 8888 open for listening. All these pods are labelled ABC.
  3. Created NodePort NP1 service:
    Port: 2222
    NodePort: 3333
    TargetPort: 8888 --> this is targeting the above Pods listener
    :
    selector:
    labels: ABC
  4. Another application (APP1) connects to NP1 service (TCP) connecting to NodePort 3333 and send payload to those 3 Pods.
  5. Payload are coming in but it only goes to Pod A. It's not distributing to other 2 pods.
  6. I understand IP Tables is used for traffic distribution. I noticed when the protocol is HTTP then the payload gets distributed to all 3 pods. But when it's TCP it only distribute to 1 Pod all the time.

Any help or insight would be great.

-- yapkm01
iptables
ipvs
kubernetes
kubernetes-ingress
kubernetes-pod

1 Answer

1/14/2020

When you put a loadbalancer in front of these 3 pods and you make requests to it, it will go into any of those 3 pods, not all 3 of them at the same time. What you are looking for is a headless service, that returns all the ips of the associated pods to work with. Further explanation in this article: https://dev.to/kaoskater08/building-a-headless-service-in-kubernetes-3bk8 hope this help.

-- paltaa
Source: StackOverflow