简体   繁体   English

有没有办法为 Kubernetes 中的传出流量保留源端口?

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

In most TCP client/server communications, the client uses a random general purpose port number for outgoing traffic.在大多数 TCP 客户端/服务器通信中,客户端使用随机通用端口号进行传出流量。 However, my client application, which is running inside a Kubernetes cluster, must use a specific port number for outgoing traffic;但是,我的客户端应用程序在 Kubernetes 集群中运行,必须使用特定的端口号进行传出流量; 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).当应用程序在外部运行时,这通常可以正常工作,但在 Kubernetes 集群内部时,源端口在从 pod 到工作节点的途中被修改(通过工作节点上的 tcpdump 验证)。

For context, I am using a LoadBalancer Service object.对于上下文,我使用的是 LoadBalancer 服务 object。 The cluster is running kube-proxy in Iptables mode.集群在 Iptables 模式下运行 kube-proxy。

So I found that I can achieve this by setting the hostNetwork field to true in the pod's spec.所以我发现我可以通过在 pod 的规范中将hostNetwork字段设置为true来实现这一点。

Not an ideal solution but gets the job done.不是一个理想的解决方案,但可以完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM