如果使用 POD 亲和性,流量是否会路由到同一节点上的 POD?

Is traffic routed to POD on same NODE if POD affinity is used?

我有两个 PODS,服务器 POD 和客户端 POD。 我的部署使用多个副本。 并使用我制作的 POD 亲和力将一对客户端和服务器节点放在同一节点上。

我的问题是来自Client的流量是否路由到同一节点上的Server POD? 如果不是,如何配置实现同节点路由?

谢谢

Pod affinity 确保并置 pods 部署到同一节点上。它不保证流量将发送到同一节点上的 pods。

您需要通过功能标记使用service topology. Kubernetes version 1.17 or later is needed for this feature and you need to enable此功能。

Service Topology enables a service to route traffic based upon the Node topology of the cluster. For example, a service can specify that traffic be preferentially routed to endpoints that are on the same Node as the client, or in the same availability zone

考虑一个集群,其中的节点标有 hostnamezone nameregion name。然后您可以设置服务的 topologyKeys 值来引导流量,如下所示。

  1. 仅到同一节点上的 endpoints,如果节点上不存在端点则失败:["kubernetes.io/hostname"].

  2. 优先于同一节点上的 endpoints,回退到同一区域中的 endpoints,然后是同一区域,否则失败:["kubernetes.io/hostname" , "topology.kubernetes.io/zone", "topology.kubernetes.io/region"]。这可能很有用,例如,在数据局部性至关重要的情况下。

  3. 优先于相同的 zone,但回退到任何可用的 endpoint 如果 none 在此 zone 中可用:["topology.kubernetes.io/zone", "*"].