kek112
kek112

Reputation: 41

Kubernetes service with port-forward does not load balance

im goofin around with K8s for my master thesis at the moment. For this im spinning up an K8s Cluster with the help of KinD. I have also developed an small flask REST API which will echo en ENV var. Now im starting 3 Services which hold a number of pods of the flask App and they are calling each other. For better understanding i have an hello svc, an world service and an world2 svc. So far so good. I have successfully deployed them and now i want to port-forward the hello svc.

kubectl --namespace test port-forward svc/hello 30000

This works fine but as soon as im starting my JMeter Application to test the load balancing features something odd happens. As you can see in the grafana dashboard the other services are happily load balancing the traffic but the svc which is port forwarded is sending all of its traffic into one hello pod.

This is my deployment: deployment.yml

Am i missing something? Or did i deploy my application wrong?

Thanks in advance!

enter image description here

Upvotes: 2

Views: 2443

Answers (2)

kek112
kek112

Reputation: 41

For all these who are interested i found a Workaround which is also closer to production.

First of all i installed MetalLB https://mauilion.dev/posts/kind-metallb/

With this LoadBalancer i declared an IP Range which ist the same as the one of my nodes. Also the service which i am exposing received the type: LoadBalancer with this grafana is now showing an equal distribution of requests.

Upvotes: 1

Arghya Sadhu
Arghya Sadhu

Reputation: 44657

Port-forward allows the use of services for convenience purposes only. Behind the scenes connects to a single pod directly. Connection will be dropped should this pod die. There is no load balancing in port forward.One pod selected by the service is chosen and all traffic is forwarded there for the entire lifetime of the port forward command.I would suggest using NodePort type service if you need to test load balancing via JMeter from outside the kubernetes cluster.

Upvotes: 5

Related Questions