Unable to get a websocket app work through kubernetes ingress-nginx in a non-root context path
So basically this:
nginx.ingress.kubernetes.io/rewrite-target: /
is stripping the /ws
from the request (combined with path: /ws
) that gets sent to the backend everytime your browser tries to issue a WebSocket connection request. The backend expects /ws
when it receives a connection request.
If you specify path: /mypath
and /mypath/*
it works (works for me):
apiVersion: extensions/v1beta1kind: Ingressmetadata: name: ws-example-svc annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/rewrite-target: /spec: rules: - host: myhostname.com http: paths: - backend: serviceName: ws-example-svc servicePort: 80 path: /mypath - backend: serviceName: ws-example-svc servicePort: 80 path: /mypath/*
https://kubernetes.github.io/ingress-nginx/user-guide/miscellaneous/#websockets
If the NGINX ingress controller is exposed with a service type=LoadBalancer make sure the protocol between the loadbalancer and NGINX is TCP.
Sample AWS L4 Service https://github.com/kubernetes/ingress-nginx/blob/master/deploy/provider/aws/service-l4.yaml#L11
# Enable PROXY protocolservice.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*"