Is there a way to preserve the source port for outgoing traffic in Kubernetes?

Viewed 281

In most TCP client/server communications, the client uses a random general purpose port number for outgoing traffic. However, my client application, which is running inside a Kubernetes cluster, must use a specific port number for outgoing traffic; this is due to requirements by the server.

This normally works fine when the application is running externally, but when inside a Kubernetes cluster, the source port is modified somewhere along the way from the pod to the worker node (verified with tcpdump on worker node).

For context, I am using a LoadBalancer Service object. The cluster is running kube-proxy in Iptables mode.

1 Answers

So I found that I can achieve this by setting the hostNetwork field to true in the pod's spec.

Not an ideal solution but gets the job done.

Related