7

If you scale up a Pod in Openshift3, all requests coming from the same client IP address are sent to container which has the session associated.

Is there any configuration to disable sticky sessions? How can I manage the options of internal HAProxy in Openshift?

Carlos Alberto
  • 7,761
  • 13
  • 52
  • 72

2 Answers2

14

For posterity, and since I had the same problem, I want to document the solution I used from Graham Dumpleton's excellent comment.

As it turns out, a cookie is set during the first request that redirects subsequent requests to the same back-end. To disable this behavior on a per-route basis:

oc annotate routes myroute haproxy.router.openshift.io/disable_cookies='true'

This prevents the cookie from being set and allows the balance algorithm to select the appropriate back-end for subsequent requests from the same client. To change the balance algorithm:

oc annotate routes myroute haproxy.router.openshift.io/balance='roundrobin'

With these two annotations set, requests from the same client IP address are sent to each back-end in turn, instead of the same back-end over and over.

Lex Scarisbrick
  • 1,540
  • 1
  • 24
  • 31
4

oc set env dc/router ROUTER_TCP_BALANCE_SCHEME=roundrobin will change the load balancing algorithm haproxy uses for routes it just passes through (default is source). ROUTER_LOAD_BALANCE_ALGORITHM will change it for routes where it terminates TLS (default us leastconn).

More info on changing the internals of how haproxy works in the OCP 3.5 docs .

Mark McKinstry
  • 2,536
  • 1
  • 15
  • 8
  • 3
    See also route specific annotations to override it for specific routes rather than whole proxy configuration. https://docs.openshift.com/container-platform/3.5/architecture/core_concepts/routes.html#route-specific-annotations – Graham Dumpleton Jun 22 '17 at 04:59
  • I also customized adding the option: oc set env dc/spring-boot-samples ROUTER_TCP_BALANCE_SCHEME=roundrobin ROUTER_LOAD_BALANCE_ALGORITHM=roundrobin – Carlos Alberto Jun 22 '17 at 14:06