<p>I have a problem with my ingress, basically in my k8s cluster there are two chat and notification microservices, these are two microservices which, in addition to exposing APIs, expose a web socekt with socket.io and a normal websocket.</p>
<p>Chat</p>
<pre><code>const {Server} = require(&quot;socket.io&quot;);
const io = new Server(server); 

io.on('connection', (socket) =&gt; {
        console.log('New connection started', socket.id);
});
</code></pre>
<p>Notification</p>
<pre><code>const WebSocket = require('ws');
const wss = new WebSocket.Server({server});

wss.on('connection', (ws) =&gt; {
    console.log('Client connected', ws);
});
</code></pre>
<p>Each microservice is deployed with associated service on my k8s cluster.</p>
<p>But now I can't establish socket and web-socket connections through my ingress, here is my config:</p>
<pre><code>kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/use-regex: 'true'
    nginx.ingress.kubernetes.io/proxy-body-size: 64m
    nginx.ingress.kubernetes.io/proxy-read-timeout: '3600'
    nginx.ingress.kubernetes.io/proxy-send-timeout: '3600'
    nginx.ingress.kubernetes.io/proxy-connect-timeout: '3600'
spec:
  rules:
    - host: demo.local.home
      http:
        paths:
          - path: /ct(/|$)(.*)
            pathType: Prefix
            backend:
              service:
                name: ct-svc
                port:
                  number: 8110
          - path: /
            pathType: Prefix
            backend:
              service:
                name: ct-svc
                port:
                  number: 8210
          - path: /nt(/|$)(.*)
            pathType: Prefix
            backend:
              service:
                name: ntf-svc
                port:
                  number: 8111
          - path: /demo
                    pathType: Prefix
                    backend:
                      service:
                        name: dm-svc
                        port:
                          number: 8290
</code></pre>
<p>The services respond correctly via REST API, but I can't connect to the socket.io and web-socket, would you have any advice to make my configuration work?</p>

HittingMyCode
<p>I finally managed to solve the problem, here is the final configuration:</p>
<pre><code>metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/use-regex: 'true'
    nginx.ingress.kubernetes.io/proxy-body-size: 64m
    nginx.ingress.kubernetes.io/proxy-read-timeout: '3600'
    nginx.ingress.kubernetes.io/proxy-send-timeout: '3600'
    nginx.ingress.kubernetes.io/proxy-connect-timeout: '3600'
spec:
  rules:
    - host: demo.local.home
      http:
        paths:
          - path: /ct(/|$)(.*)
            pathType: Prefix
            backend:
              service:
                name: ct-svc
                port:
                  number: 8110
          - path: /nt(/|$)(.*)
            pathType: Prefix
            backend:
              service:
                name: ntf-svc
                port:
                  number: 8111
          - path: /demo
                    pathType: Prefix
                    backend:
                      service:
                        name: dm-svc
                        port:
                          number: 8290
</code></pre>
<p>with:</p>
<ul>
<li>socket.io host: <a href="http://demo.local.home/ct/" rel="nofollow noreferrer">http://demo.local.home/ct/</a></li>
<li>websocket host: ws://demo.local.home/nt/</li>
</ul>
