【发布时间】:2020-02-24 16:42:17
【问题描述】:
假设我有三个服务,ServiceA、ServiceB 和 ServiceC。 ServiceA 和 ServiceB 都调用 ServiceC。我想部署一个新版本的 ServiceC,但只想从 ServiceB 发送流量进行测试。是否有考虑到“调用服务”的路由配置?
【问题讨论】:
标签: istio
假设我有三个服务,ServiceA、ServiceB 和 ServiceC。 ServiceA 和 ServiceB 都调用 ServiceC。我想部署一个新版本的 ServiceC,但只想从 ServiceB 发送流量进行测试。是否有考虑到“调用服务”的路由配置?
【问题讨论】:
标签: istio
您可以使用virtual service,或虚拟服务和destination rule。
带标签,例如here
带有应用和版本标签的部署:我们建议在部署中添加明确的应用标签和版本标签。将标签添加到使用 Kubernetes 部署部署的 pod 的部署规范中。应用和版本标签将上下文信息添加到 Istio 收集的指标和遥测数据中。
应用标签:每个部署规范都应该有一个不同的应用标签,并具有有意义的值。应用标签用于在分布式跟踪中添加上下文信息。
版本标签:此标签表示特定部署对应的应用程序版本。
每个路由规则都与一个或多个服务版本相关联(参见文档开头的词汇表)。与版本相关的权重决定了它接收的流量比例。例如,以下规则会将“reviews”服务的 25% 流量路由到带有“v2”标签的实例,并将剩余流量(即 75%)路由到“v1”。
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews-route
spec:
hosts:
- reviews.prod.svc.cluster.local
http:
- route:
- destination:
host: reviews.prod.svc.cluster.local
subset: v2
weight: 25
- destination:
host: reviews.prod.svc.cluster.local
subset: v1
weight: 75
以及相关的 DestinationRule
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: reviews-destination
spec:
host: reviews.prod.svc.cluster.local
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
或
还可以将流量拆分到两个完全不同的服务中,而无需定义新的子集。例如,以下规则将 25% 的流量转发到 reviews.com,将 75% 的流量转发到 dev.reviews.com
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews-route-two-domains
spec:
hosts:
- reviews.com
http:
- route:
- destination:
host: dev.reviews.com
weight: 25
- destination:
host: reviews.com
weight: 75
编辑
所以实际上你必须为你的 serviceC 1.0 和 2.0 添加标签,虚拟服务看起来像这样。
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews-route-two-domains
spec:
hosts:
- reviews.com
http:
- match:
- sourceLabels:
svc: A
- route:
- destination:
host: serviceC
label: v1
- match:
- sourceLabels:
svc: B
- route:
- destination:
host: serviceC
label: v2
查看我使用 sourceLabels here 的另一个答案
如果您还有其他问题,请告诉我。
【讨论】: