kubernetesload-balancingkubernetes-serviceaffinityround-robin

How to change K8S Service Load Balancer algorithm\affinity behavior


basic question, I have the following LB:

apiVersion: v1
kind: Service
metadata:
  name: my-lb
spec:
  type: LoadBalancer
  ports:
  - name: my-udp-port
    port: 54545
    protocol: UDP
  selector:
    app: my-app

And for some reason the traffic is not distributed equally (single pod get's ~99% of the traffic). Any idea how to control it?


Solution

  • When an resource is created as "LoadBalancer" service type in k8s by default it doesn't offer load balancing. If you are looking for proper load balancing then this service needs to be associated with external load balancer of the cloud provider. For more details please refer k8s service documentation

    Depending on the cloud provider the algorithm can be chosen at external load balancer end.

    Affinity is an different topic and this also can be achieved using external load balancer.

    In k8s service abstraction / service proxies is provided by kube-proxy and it has different modes, more details are in their k8s documentation.