Ingress with support for websocket

Hello all, I am trying to set up ingress for Signal K for the following webpage app (demo): Signal K Server.

I have set this up in the dev rep here: ha-addons/signalk2mqtt at dev · corvy/ha-addons · GitHub. To test it I suggest you pull the dev rep and save it to the local HA instance in /addons/ folder.

The design is currently that I have created a simple add-on running signalk and nginx. The webpage is presented via ingress the following way: HA → Ingress to port 3030 → nginx on port 3030 → signalk on 3000. When I connect to nginx directly on 3030 the web interface works, if I connect to 3000 it also works. Connecting through ingress I get “cannot connect to server”. My investigations shows that when I connect via ingress websocket does not work. Logs shows for instance this error:

actions.js:162 WebSocket connection to 'wss://ha.anonymized.com/signalk/v1/stream?serverevents=all&subscribe=none&sendMeta=all' failed:. 
/api/hassio_ingress/…admin/#/dashboard:1 Uncaught (in promise) SyntaxError: Unexpected non-whitespace character after JSON at position 3.

In the SignalK logs I get no significant errors so I think the wss connection does not go back to the addon. How do I attack this? Is it possible to rewrite the wss URL through the nginx reverse proxy? How would I do that and to what? What URL should I use for the wss connection? The url slug looks like this: https://ha.anonymized.com/local_signalk2mqtt/ingress but that is probably not correct.

Any pointers? Anyone that could help me. You could easily test it yourself by downloading from git and test via the local rep in /addons.

Thank you!

I will leave this ingress here in case someone wants to implement in in k8s nginx…
This works perfect for me… I just only changed the home assistant server port to 80 (via configuration.yaml) + added exception for reverse proxy in configuration.yaml

Configuration YAML:

http:
  server_port: 80
  use_x_forwarded_for: true
  trusted_proxies:
  - 192.168.200.100
  - 192.168.200.101
  - 192.168.200.102
  - 192.168.200.103
  - 192.168.200.104
  - 192.168.200.190
  - 192.168.200.191
  - 192.168.200.192
  - 192.168.200.193
  - 192.168.200.194
  - 192.168.200.195

Ingress:

kind: Ingress
metadata:
  name: home-assistant-ingress
  namespace: default
  annotations: 
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/server-snippets: |
      location /api/websocket {
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
        }
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - example.com
    secretName: home-assistant-cert
  rules:
    - host: example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: haas
                port:
                  # number: 80
                  name: haas
1 Like

Thank you :slight_smile: This is to be able to connect to HA via proxy, my project is to connect to an addon I have made that is running on my HA instance. So this does not really help me, but could maybe be valuable for others.

Thanks for replying!

I’ve just deployed Home Assistant in k8s in my homelab, and this helped me to set up ingress, thank you!