How to load balancing to pods of service?

Hi, I’m using Kong kubernetes ingress as API gateway. It proxies to an k8s internal service called “device-execer”.

How should I load balance the requests to specific pod of the service?

Two possible scenarios:

  1. By user IP. For all requests from a IP, proxies to a fixed pod.
  2. By url. For all requests to /dev/11:22:33:44:55, to pod1, while those to /dev/aa:bb:cc:dd:ee:ff, to pod2.

Are there solutions for the either of two scenarios?

I’m new to Kong. Thanks a lot!

Please look into the upstream entity of Kong, and read up on KongIngress Custom Resource, which allows you to specify the load-balancing strategies.

You can do hash based load balancing to route request based on client IP.

@Tieske can give more details on which properties to use.

See the upstream entity here: https://docs.konghq.com/2.0.x/admin-api/#create-upstream

The approach uses “consistent-hashing”, there are a number of properties that can be used as the input for the hash. The upstream-property you’re looking for is the hash_on field (and hash_fallback).

Also read the LB reference: https://docs.konghq.com/2.0.x/loadbalancing/

Thanks a lot! @Tieske and @hbagdi

if the target address is a k8s svc address,not endpoint ips,how to do load balancing.

You can only load-balance if Kong is forward traffic directly to pods. If kube-proxy is involved in the middle, Kong cannot do load-balancing.

@hbagdi If the kube-proxy is involved and Kong don’t do load-balancing, what is the proper setting for the upstream slots setting which is set by default to 10000?

The documentation says that a slots of 100 is needed by targets, however if the kube-proxy is involved, do we still need 100 slots by target?

Using service-upstream/kube-proxy to handle traffic won’t create an upstream at all, so none of the upstream/target-related settings are relevant.