Istio setup for socket.io

Hi! I have a socket.io powered site running in Istio. The issue is that socket.io works only when there is a single replica of that site. When I add more instances, it stops working. Error message in browser is

{"code":1,"message":"Session ID unknown"}

My guess that issue is caused by round robin LB, when socket.io requests from one client reach different servers.

I have websocketUpgrade: true set in VirtualService setup, but that does not seem to be enough.

Could you please clarify how to enable session affinity with Istio / Kubernetes?

Thanks

Istio and the Envoy dataplane inside support “soft” persistence using HTTP cookies or the Source IP:

see the comment that says “The affinity to a particular destination host will be lost when one or more hosts are added/removed from the destination service.” Soft affinity is usually used if there’s a cache advantage to going to the same server, but not a loss of functionality if you get rebalanced to a different server occasionally.

I’m not aware of any way to get a stronger affinity in Istio currently.

1 Like

Thanks, @AndrewJenkins. I noticed that socket io adds cookie io to it’s requests. I added the following to my DestinationRule and it seems to work

  trafficPolicy:
    loadBalancer:
      consistentHash:
        httpCookie:
          name: io
          ttl: 0s