Websockets + Spring boot + Kubernetes
An adequate way to handle this would be to use "sticky sessions". This is where the user is pinned down to a specific pod based on the setting of a cookie.
Here is an example of configuring the Ingress
resource object to use sticky sessions:
## https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/affinity/cookie#apiVersion: extensions/v1beta1 kind: Ingress metadata: name: nginx-test-sticky annotations: kubernetes.io/ingress.class: "nginx" ingress.kubernetes.io/affinity: "cookie" ingress.kubernetes.io/session-cookie-name: "route" ingress.kubernetes.io/session-cookie-hash: "sha1"spec: rules: - host: $HOST http: paths: - path: / backend: serviceName: $SERVICE_NAME servicePort: $SERVICE_PORT
Now with that being said, the proper way to handle this would be to use a message broker or a websocket implementation that supports clustering such as socketcluster (https://socketcluster.io).