How to Configure Traefik for layer 4 with sticky session health Web API and web sockets

Hi,
I am using windows environment not docker just simple windows server 2019 and it will be under company VPN. I have a backend server that host a single page application and a Web API plus web socket for push event both on same VM box but different port for SPA and Web API. Behind the web api I have few of services communicating over message bus. I have hosted two instance of my backend on two different machine and I want the Traefik load balancer in front of them to balance the load equally on both my backend server. I want sticky sessions, health and web socket. Is it possible using layer 4 like TCP router and TCP service or I have to use the HTTP router and HTTP services that might be slow on layer 7?

Thanks & Regards
IK

I think is not possible because sticky session relay on an HTTP Cookie.
Best regards, Marcelo.

PD: Here a sample whoami with Sticky session definition:

services:
  whoami:
    image: traefik/whoami:v1.6.0
    hostname: whoami-{{.Task.Slot}}.mydomain.com
    deploy:
      mode: replicated
      replicas: 3
      labels:
        - traefik.enable=true
        - traefik.docker.network=lb_network
        - traefik.constraint-label=traefik-public
        - traefik.http.routers.whoami.rule=Path(`/whoami`)
        - traefik.http.services.whoami.loadbalancer.server.port=80
        - traefik.http.services.whoami.loadbalancer.sticky=true
        - traefik.http.services.whoami.loadbalancer.sticky.cookie.name=StickyCookie

and here cookie response from service:

mochoa@pocho:~/docker/traefik$ curl -v --resolve whoami-1.mydomain.com:80:127.0.0.1 -H whoami-1.mydomain.com http://whoami-1.mydomain.com/whoami
* Added whoami-1.mydomain.com:80:127.0.0.1 to DNS cache
* Hostname whoami-1.mydomain.com was found in DNS cache
*   Trying 127.0.0.1:80...
* TCP_NODELAY set
* Connected to whoami-1.mydomain.com (127.0.0.1) port 80 (#0)
> GET /whoami HTTP/1.1
> Host: whoami-1.mydomain.com
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Length: 390
< Content-Type: text/plain; charset=utf-8
< Date: Sat, 09 Jan 2021 18:47:26 GMT
< Set-Cookie: StickyCookie=http://10.0.4.8:80; Path=/
< 
Hostname: whoami-2.mydomain.com
IP: 127.0.0.1
IP: 10.0.4.8
IP: 172.18.0.3
RemoteAddr: 10.0.4.13:52202
GET /whoami HTTP/1.1
Host: whoami-1.mydomain.com
User-Agent: curl/7.68.0
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.18.0.1
X-Forwarded-Host: whoami-1.mydomain.com
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: 2b67f18683a8
X-Real-Ip: 172.18.0.1
1 Like

Thanks. Can we run Traefik directly from windows 2016 Server without using docker?

I don't know. But if you install WSL2 support on Windows it will be able to run natively an Ubuntu 20.04 version which for sure runs Traefik.
Best regards, Marcelo.

The Traefik code is in Go, i think it should work on windows without any issue?

Hello @imtiazpk82,

Thanks for your interest in Traefik!

You can find the appropriate executable in each release: Release v2.4.0 · traefik/traefik · GitHub