SignalR Websocket via K8S ingress

1/28/2020

I have an simple SignalR Client Server setup, where my Server consist of an Webapplication running in a kubernetes cluster, exposing a service via an ingress controller as such:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    # Enable PROXY protocol
    service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*"
  name: coreapilocal-ingress
spec:
  rules:
  - host: coreapilocal.localhost
    http:
      paths:
      - backend:
          serviceName: coreapilocal-service
          servicePort: 80
        path: /
      - backend:
          serviceName: coreapilocal-service
          servicePort: 80
        path: /*

And a HTML Client that tries to invoke a SignalR Server method via the ingress? But for some reason is this call being ignored for some reason?

I read somewhere that Http is being stripped by the ingress? and thereby can't recognize the call? Is there someway to avoid this? or get around this?

I tried above given a different post I found here in SE, but this does not seem to work in my case..

-- kafka
kubernetes
nginx-ingress
signalr

1 Answer

1/28/2020

For SignalR to work (and in general for WebSockets) you should enable Sticky Sessions

Add the annotation nginx.ingress.kubernetes.io/affinity: "cookie" to the ingress workload definition:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    # Enable PROXY protocol
    service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*"
    nginx.ingress.kubernetes.io/affinity: "cookie"
  name: coreapilocal-ingress
spec:
  rules:
  - host: coreapilocal.localhost
    http:
      paths:
      - backend:
          serviceName: coreapilocal-service
          servicePort: 80
        path: /
      - backend:
          serviceName: coreapilocal-service
          servicePort: 80
        path: /*
-- Alberto
Source: StackOverflow