Kubernates Ingress and path based routing for websocket service

Hi,
I am a newbie user of Traefik. I have started to play with it and leveraging it as Ingress Controller.

The scenario I want to support is quite easy, I would like to define an ingress for a websocket service in Kubernates that in turn resides in front of a-pod-replicated websocket server.

The idea is:
Ingress --> Service --> WebSocket Pods

Since is not yet at a production-ready solution, I am using an Helm chart to achieve Traefik in my K8s cluster (based on an image of Traefik at v.1.7)

helm install stable/traefik

The nice thing is that if I use an host-based configuration, everything is working smootly at first shot ! :heart_eyes:

kind: Ingress
metadata:
  name: wsk-ingress
  annotations:
    kubernetes.io/ingress.class: traefik
  rules:
  - host: ws.traefik.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: wsk-svc
          servicePort: 80

The clinet is able to connect at the given host / port immediately through Traefik configuration.

What i want now to achieve is a path-based routing.
The configuration is sligthly different:

Ingress (path /wsk) --> Service (path /) --> WebSokcet Pods

Even if I expected it to be straightforward, I am unable to achieve the same result. :face_with_raised_eyebrow:
Here is what I tried:

kind: Ingress
metadata:
  name: wsk-ingress
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.frontend.rule.type: PathPrefixStrip
    traefik.ingress.kubernetes.io/rewrite-target: /
  rules:
  - host: ws.traefik.example.com
    http:
      paths:
      - path: /wsk
        backend:
          serviceName: wsk-svc
          servicePort: 80

Now if I try to change the client configuration, adding the path part, the client fails at some point and I have no idea why. But looking at the error obtained, it seems really a proxy error at websocket level when handshaking between client and server.

I have seen similar problems in static scenarios using NGINX as Proxy and the suggestion to solve is inside official Doc for Websocket Proxing, which adds specific headers for such a reverse proxing.
Since I don't know if this is related in some way, nor whether I am totally wrong, I would like to share here my experience.
Maybe this is a problem which was overcame in Traefik 2.0.

I want to clarify that my issue is not related at all to load balancing websockets (e.g. sticky connection), which I solved at a Kubernates-service level. I guess that mine is a more specific Ingress issue related to websocket handshaking connections or rewriting rules (and moreover ingress host-based works like a charm)

Thanks in advance
Sergio

2 Likes