是否可以将 virtualService 和 Destination 应用于指定版本的 POD

Is it possible to apply virtualService and Destination to the specified version of the POD

我有两个http服务A和B,每个服务有两个版本v1和v2。

如果 A(v1) 调用 B,例如。使用http://b:8080,B(v1)和B(v2)都能接听电话

当A(v2)呼叫B时,只有B(v2)接到呼叫。

在这种情况下,我应该如何定义 virtualService 和目标规则?

您需要将流量来源的 pod 与 sourceLabels 相匹配,并将其路由到特定的 subsets。这是一个可能看起来像的例子:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: route-av1-bv1-2
spec:
  hosts:
  - service-b
  http:
#Match the traffic from App-A-version-1 towards App-B versions 1 & 2
  - match:
    - sourceLabels:
        app: av1
    - route:
      - destination:
          host: service-b
          subset: v1
    - route:
      - destination:
          host: service-b
          subset: v2  
#Match the traffic from App-A-version-2 towards only App-B-version-2
  - match:
    - sourceLabels:
        app: av2
    - route:
      - destination:
          host: service-b
          subset: v2

DestinationRule:

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: route-av1-bv1-2
spec:
  host: service-b
  subsets:
  - name: v1
    labels:
      app: bv1
  - name: v2
    labels:
      app: bv2

Istio traffic management 部分很好地描述了 VirtualServiceDestinationRule 以及一些很好的示例。