How to move a TCP connection to another pod?

On Linux servers and Windows servers, processes can surrender connected sockets’ handles (sendmsg and SCM_RIGHTS on Linux, and WSADuplicateSocket for Windows) and hand it off to another process so that the connection may be resumed in a different context.

Is it possible to do something similar in Kubernetes? In this case, the entities in question are pods rather than processes, and the pods are hosted on the same node. Ideally, the connection should not be dropped or reset in the process, so as to prevent the client from having to reconnect.

It doesnt support natively. You can explore istio / envoy proxy in that case envoy proxy side car with some config tweaks will be able to handle it but I doubt it will prevent reconnection though it will do natively retry attempt by handing it at istio sidecar layer.

Kubernetes networking is built around the assumption that each pod is an independent entity with its own network namespace, making it difficult to directly share socket handles between pods.

1 Like

I see. Thank you for the answer! I’ll consider my options

In Kubernetes, direct socket handoff between pods, similar to transferring sockets between processes on Linux or Windows, is not natively supported due to the stateless and ephemeral nature of pods. However, you can achieve connection stability through alternative methods. One option is using sticky sessions with a load balancer to ensure a client consistently connects to the same pod, or StatefulSets to provide stable pod identities for long-lived connections. Another approach is using a sidecar container within the same pod to manage connections or leverage shared volumes for inter-process communication. While service meshes like Istio can help manage connection resilience, they don’t directly support socket handoff between pods, but they minimize disruptions during pod transitions.

4 Likes