使用 Istio 在 K8s 集群内部路由加权流量



我有 2 个应用程序(Web 和 Api(,分别有 2 个服务和 2 个 Istio 虚拟服务。此外,每个服务有 2 个版本(v1 和 v2(。

我想做三件事-

  1. 对于 Web,除测试用户之外的所有流量将仅100%路由到版本v1

  2. 对于
  3. Web,对于测试用户流量将仅100%路由到版本v2(反之亦然(。在上线之前,QA 团队将对版本 v2 进行测试,一旦经过 QA 团队验证,将每个用户的流量移动到100%v2,并删除版本v1

  4. 对于 Api,流量将分配v1(稳定版(的95%,版本v2(发布(的5%。

网页清单文件:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: web-vs
spec:
hosts:
- web.example.com
http:
- match:
- headers:
end-user:
exact: test-user
route:
- destination:
host: web-svc
subset: v2
- route:
- destination:
host: web-svc
subset: v1
---
apiVersion: v1
kind: Service
metadata:
name: web-svc
labels:
app: web
spec:
ports:
- name: http
port: 3000
targetPort: 3000
selector:
app: web

API 清单文件:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: api-vs    -------------> #1
spec:
hosts:
- api-svc
http:
- route:
- destination:
host: api-svc
subset: v1
weight: 95
- destination:
host: api-svc
subset: v2
weight: 5
---
apiVersion: v1
kind: Service
metadata:
name: api-svc    -------------> #2
labels:
app: api
spec:
ports:
- name: http
port: 8000
targetPort: 8000
selector:
app: api

流量路由策略-

  1. 当我们点击 urlweb.example.com时,它将提供来自服务web-svc的流量。(这已设置(

  2. 在后端,服务 web-svc 将在内部调用服务 api-svc
  3. ,服务api-svc会将流量95% 分配给 v1,将5%分配给v2(这就是我正在努力处理的路由。

我认为问题出在缩进和主机上。从 Istio 文档中,尝试如下:

hosts:
- api-svc
http:
- route:
- destination:
host: api-svc
subset: v1
weight: 95
- destination:
host: api-svc
subset: v2
weight: 5

已编辑:目标主机。

最新更新