Kubernetes:将传入流量路由到特定 Pod

mic*_*cha 7 network-programming kubernetes google-kubernetes-engine istio kubernetes-ingress

我想在 Google Kubernetes Engine 中部署许多 Pod,然后通过子域(如 pod-name-or-label.mydomain.com)或路径路由(如 protocol://mydomain.com:7878/pod-)建立到每个特定 Pod 的 TCP 连接名称或标签。

我研究过不同的方向,例如 Istio 或 nginx-ingress,但在我看来这太复杂了。

难道没有一个简单的解决方案吗?

che*_*ohi 2

对于Istio,您可以使用VirtualService通过DestinationRules定义来控制到目标子集的路由规则

DestinationRule将通过指定的标签pod路由到目标Pod

请求流程将如下:

+--------------------+
|                    |
|    Istio Gateway   |
|                    |
|                    |
+---------+----------+
          |traffic incoming
          |
+---------v----------+
|                    |
|   VirtualService   |
|                    |
|                    |
+---------+----------+
          |route to subset by the routing rules
          v

+--------------------+
|                    |
|  DestinationRules  |
|                    |
|                    |
+---------+----------+
          |route traffic to target pods
          v

+--------------------+
|                    |
|                    |
|       Pods         |
|                    |
+--------------------+
Run Code Online (Sandbox Code Playgroud)

正如 @ericstaples 所说,您应该使用不同的pod 标签创建不同的部署,以实现分离目标pod 的流量,示例:

  1. 创建一个 pod 标签为 t1 的部署
  2. 在DestinationRule中创建子集:选择 t1 标签 pod 作为子集 s1
  3. 控制VirtualService中路由到s1子集的流量
  4. s1到目标 Pod 的路由

另外,对于公开Gateway ,您可以像 ** Kubernetes** 其他服务一样使用ClusterIPNodePort ,请参阅Istio Traffic的更多内容。

有一些参考也许会有帮助:

https://istio.io/docs/concepts/traffic-management/

https://istio.io/docs/tasks/traffic-management/request-routing/