Search code examples
kuberneteswebsocketkubernetes-ingressnginx-ingressportainer

NginxInc/kubernetes-ingress - Opening portainer websocket connections - Passing headers


Reporting a solution here for future reference as I couldn't find any single resource when I was implementing this:

Using the nginxinc/kubernetes-ingress controller not the kubernetes/ingress-nginx.

Problem started in portainer v2.1.1, but if you ever need to create an ingress rule and pass headers through, or apply any specific rules.

Issue codes:

Unable to upgrade the connection (err=websocket: the client is not using the websocket protocol: 'upgrade' token not found in 'Connection' header) (code=500)

WebSocket connection to 'ws://portainer.example.com/.....// failed

Solution

  • Following the Nginx websocket proxying guide A minimal solution using Nginx snippets:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: portainer-ingress
      namespace: portainer
      annotations:
        nginx.org/location-snippets: |
          proxy_set_header   Upgrade            $http_upgrade;
          proxy_set_header   Connection         "upgrade";
        
    spec:
      ingressClassName: nginx
      rules:
        -  host: portainer.example.com
           http:
            paths:
              - path: /
                backend:
                  service:
                    name: portainer
                    port:
                      number: 9000
                pathType: Prefix
    

    Running Nginx ingress controller version v1.10.1 installed using manifests

    helm.sh/chart: ingress-nginx-3.23.0
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/version: 0.44.0
    

    I hope this helps someone as a reference