Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openshift Route is not load balancing from Service pods

I have tried before on Openshift Origin 3.9 and Online. I have deployed a simple hello world php app on Openshift. It has a Service and a Route.

When I call the route, I am getting expected output with Hello world and the Pod IP. Let's call this pod ip as 1.1.1.1

Now i deployed same app with small text change with same label under same Service. Let's call this pod ip as 2.2.2.2

I can see both pods running in a single Service. Now when I call the route, it always shows Podip 1.1.1.1 My route never hits the second pod.

My understand is Route will call the Service and Service will load balance between available pods.

But it isn't happening. Any help is appreciated.

like image 402
John Seen Avatar asked Feb 06 '19 12:02

John Seen


2 Answers

The default behavior of the HAProxy router is to use a cookie to ensure "sticky" routing. This enables sessions to remain with the same pod. https://docs.openshift.com/container-platform/3.11/architecture/networking/routes.html

If you set a haproxy.router.openshift.io/disable_cookies annotation on the route to true it should disable this behavior.

like image 109
Will Gordon Avatar answered Oct 14 '22 16:10

Will Gordon


For those who came here looking for solution; Both answers by Daein Park and Will Gordon are true.

Here is a simple catch:

  1. If you are calling your pod externally it goes from Router to Service to Pod. If haproxy.router.openshift.io/disable_cookies annotation is not set to true on the Router, service always forwards to the same pod.

    Also after disabling sticky routing with annotation above you can select a loadbalancing algorithm with: haproxy.router.openshift.io/balance as key and one of [source,roundrobin,leastconn] as value

  2. If you are calling your pod internally from another pod. It goes from Service to Pod. Service does the round robin loadbalancing just fine with default configuration.

So you should:

  • Add the said annotation to your router if you want your service exposed by a router.
  • Do nothing if you want your service to be accessed only internally

(Tested on Openshift 4.2.28)

like image 35
Ghokun Avatar answered Oct 14 '22 17:10

Ghokun