Websockets load balancing with HAProxy

2/14/2019

I'm trying to configure an HAProxy ingress controller to load-balance properly connections to websocket. I tried to raise the value timeout-client, timeout-server and timeout-connect but without success.

ingress.yaml

kind: Ingress
metadata:
  namespace: test-deploy
  name: app-test
  labels:
    app: app-test
  annotations:
    ingress.kubernetes.io/rewrite-target: /
    ingress.kubernetes.io/timeout-connect: "5000"
    ingress.kubernetes.io/timeout-client: "5000"
    ingress.kubernetes.io/timeout-server: "5000"
    ingress.kubernetes.io/timeout-tunnel: "3600"
spec:
  rules:
    - host: k8s-test.local.lan
      http:
        paths:
          - path: /app-test
            backend:
              serviceName: app-test
              servicePort: 9000
-- Quijote
haproxy
kubernetes
kubernetes-ingress
websocket

1 Answer

2/21/2019

I haven't found confirmation about websockets support in the HAProxy documentation, but this post on Quora stated that it works great. You may need to adjust client/server/tulnnel timeouts and sometimes match and route websockets traffic to the correct backend destination.

You can check actual haproxy-ingress confgiration using the following command:

kubectl exec -ti haproxy-ingress-pod-name -n ingress-controller -- cat /etc/haproxy/haproxy.cfg

If you have more than one ingress in the cluster you may need to specify a proxy class in the annotation for every Ingress object that should be used by HAProxy ingress:

kubernetes.io/ingress.class: "haproxy"

HAProxy ingress is pretty much the same HAProxy with the capability to use Kubernetes Ingress objects to update it's configuration. You can find more information about configuring HAProxy and HAProxy Ingress in the articles:

Hope it would be helpful to you.

-- VAS
Source: StackOverflow