4

I have simple WebSocket connection from my browser to a service inside Rancher. I tried to connect to the service in 2 ways:

1) directly to the service:

browser ---> service

2) via Rancher's Load Balancer:

browser ---> Load Balancer ---> service

In the first case everything is fine: the connection is established and the messages are sent through it.

In the 2nd case the connection is dropped in after ~50s. Messages are send through the connection correctly in both directions.

What is the reason?

EDIT: I tested in on ws and wss protocol. In both cases there is the same issue.

Simon
  • 1,099
  • 1
  • 11
  • 29

1 Answers1

3

Rancher Load Balancer internally uses HAProxy, which can be customized to your needs.

Here is an example HAProxy config for websockets:

global
  maxconn 4096
  ssl-server-verify none

defaults
  mode http
  balance roundrobin
  option redispatch
  option forwardfor

  timeout connect 5s
  timeout queue 5s
  timeout client 36000s
  timeout server 36000s

frontend http-in
  mode http
  bind *:443 ssl crt /etc/haproxy/certificate.pem
  default_backend rancher_servers

  # Add headers for SSL offloading
  http-request set-header X-Forwarded-Proto https if { ssl_fc }
  http-request set-header X-Forwarded-Ssl on if { ssl_fc }

  acl is_websocket hdr(Upgrade) -i WebSocket
  acl is_websocket hdr_beg(Host) -i ws
  use_backend rancher_servers if is_websocket

backend rancher_servers
  server websrv1 <rancher_server_1_IP>:8080 weight 1 maxconn 1024
  server websrv2 <rancher_server_2_IP>:8080 weight 1 maxconn 1024
  server websrv3 <rancher_server_3_IP>:8080 weight 1 maxconn 1024

Reference: https://rancher.com/docs/rancher/v1.6/en/installing-rancher/installing-server/basic-ssl-config/#example-haproxy-configuration

Only the relevant config can be used in "Custom haproxy.cfg" section of the LB. See screenshot: enter image description here

Here is the link for more documentation for custom haproxy in Rancher: https://rancher.com/docs/rancher/v1.6/en/cattle/adding-load-balancers/#custom-haproxy-configuration

leodotcloud
  • 1,830
  • 14
  • 15