istio.io/content/zh/blog/2018/traffic-mirroring/index.md

44 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: 用于在生产环境进行测试的 Istio 流量镜像功能
description: 介绍更安全,低风险的部署和发布到生产。
publishdate: 2018-02-08
subtitle: HTTP 流量的路由规则
attribution: Christian Posta
keywords: [traffic-management,mirroring]
target_release: 0.5
---
在非生产/测试环境中,尝试穷举一个服务所有可能的测试用例组合是个令人望而生畏的任务,在某些情况下,您会发现编写这些用例的所有工作都与实际生产用例不匹配,理想情况下,我们可以使用实时生产用例和流量来帮助说明我们可能在更人为的测试环境中错过的所测试服务的所有功能区域。
Istio 可以在这里提供帮助。随着 [Istio 0.5](/zh/news/releases/0.x/announcing-0.5) 的发布Istio 可以镜像流量来帮助测试您的服务,您可以编写类似于以下内容的路由规则来启用流量镜像:
{{< text yaml >}}
apiVersion: config.istio.io/v1alpha2
kind: RouteRule
metadata:
name: mirror-traffic-to-httpbin-v2
spec:
destination:
name: httpbin
precedence: 11
route:
- labels:
version: v1
weight: 100
- labels:
version: v2
weight: 0
mirror:
name: httpbin
labels:
version: v2
{{< /text >}}
这里有几点需要注意:
* 当流量镜像到不同的服务时,会发生在请求的关键路径之外
* 忽略对任何镜像流量的响应;流量被视为“即发即忘”
* 必须创建一个权重为 0 的路由,让 Istio 据此通知 Envoy 创建对应的集群定义;[这应该在未来的版本中解决](https://github.com/istio/istio/issues/3270)。
访问[镜像任务](/zh/docs/tasks/traffic-management/mirroring/)了解有关镜像的更多信息,并查看更多信息[在我的博客上综合处理这种情况](https://dzone.com/articles/traffic-shadowing-with-istio-reducing-the-risk-of)。