Contents

nginx-ingress Websocket Connection

Contents

I had an issue with minio web console that, it stuck at “Loading” message while viewing “Object Browser”. Another issue with portainer that shell console closed immediately. They all sound to me due to the same exact issue. I figured out with help of Browser developer tools, that it logs very same message in the console.

WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400

Solution

Adding following annotations to ingress resource did the trick.

    nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
    nginx.org/websocket-services: <name of service object>

You can see one of example ingress resource, for portainer.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
    nginx.org/websocket-services: portainer
  labels:
    app.kubernetes.io/name: portainer
  name: portainer
  namespace: portainer
spec:
  ingressClassName: default
  rules:
  - host: portainer.otuken.io
    http:
      paths:
      - backend:
          service:
            name: portainer
            port:
              number: 9000
        path: /
        pathType: Prefix
status:
  loadBalancer: {}