<p>Reporting a solution here for future reference as I couldn't find any single resource when I was implementing this:</p>
<p>Using the <a href="https://github.com/nginxinc/kubernetes-ingress" rel="nofollow noreferrer">nginxinc/kubernetes-ingress</a> controller <strong>not</strong> the <a href="https://github.com/kubernetes/ingress-nginx" rel="nofollow noreferrer">kubernetes/ingress-nginx</a>.</p>
<p>Problem started in <a href="https://github.com/portainer/portainer" rel="nofollow noreferrer">portainer v2.1.1</a>, but if you ever need to create an ingress rule and pass headers through, or apply any specific rules.</p>
<p>Issue codes:</p>
<pre><code>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
</code></pre>

Diarmuid
<p>Following the <a href="http://nginx.org/en/docs/http/websocket.html" rel="nofollow noreferrer">Nginx websocket proxying guide</a>
A minimal solution using <a href="https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-snippets/" rel="nofollow noreferrer">Nginx snippets</a>:</p>
<pre><code>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         &quot;upgrade&quot;;
    
spec:
  ingressClassName: nginx
  rules:
    -  host: portainer.example.com
       http:
        paths:
          - path: /
            backend:
              service:
                name: portainer
                port:
                  number: 9000
            pathType: Prefix
</code></pre>
<p>Running <a href="https://github.com/nginxinc/kubernetes-ingress/tree/v1.10.1" rel="nofollow noreferrer">Nginx ingress controller version v1.10.1</a> installed using <a href="https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/" rel="nofollow noreferrer">manifests</a></p>
<pre><code>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
</code></pre>
<p>I hope this helps someone as a reference</p>
