How to load balance a request on a service to a pod depending on a condition

8/31/2017

I have an app with 3 nodes running with a service, which uses zookeeper to elect a leader. And I want the requests to the service to be redirected to a certain pod, depending if it's leader or not. I have a http method in my app that returns if it's leader or not (if this helps in any way).

-- user8543888
kubernetes

2 Answers

9/4/2017

I'm not aware of a k8s feature for doing this.

What I would do: write a little application which looks for the endpoints of the existing service, searches the current leader, and creates/updates a 2nd service without selector (https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors) with an endpoint pointing to the leader. Then you can use that new service for your dashboard.

-- slintes
Source: StackOverflow

9/1/2017

To do that, use a StatefulSet, for example, following the example here.

-- Michael Hausenblas
Source: StackOverflow