Openshift Route is not load balancing from Service pods
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.
For those who came here looking for solution; Both answers by Daein Park and Will Gordon are true.
Here is a simple catch:
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 totrue
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 valueIf 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)
My understand is Route will call the Service and Service will load balance between available pods.
Typically your knowledge is right. Let's test it on your env as follows.
# oc describe svc webName: webNamespace: testLabels: app=webAnnotations: openshift.io/generated-by=OpenShiftNewAppSelector: app=web,deploymentconfig=webType: ClusterIPIP: 172.30.6.8Port: 8080-tcp 8080/TCPTargetPort: 8080/TCPEndpoints: 1.1.1.1:8080,2.2.2.2:8080Session Affinity: NoneEvents: <none>
Session Affinity
is None
as default value, it means round robin
for requests.
You can check the requests access as round robin
manner by looping curl
with monitoring the pods
using oc logs
or index.html
response body (if the contents is different).
while :; do curl http://172.30.177.72:8080/index.html; sleep 1; done1.1.1.1:80802.2.2.2:80801.1.1.1:8080 2.2.2.2:8080...