kubectl apply -f web-frontend.yaml 创建部署和服务 。
apiVersion: apps/v1 kind: Deployment metadata:name: customers-v1labels:app: customersversion: v1 spec:replicas: 1selector:matchLabels:app: customersversion: v1template:metadata:labels:app: customersversion: v1spec:containers:- image: gcr.io/tetratelabs/customers:1.0.0imagePullPolicy: Alwaysname: svcports:- containerPort: 3000 --- apiVersion: apps/v1 kind: Deployment metadata:name: customers-v2labels:app: customersversion: v2 spec:replicas: 1selector:matchLabels:app: customersversion: v2template:metadata:labels:app: customersversion: v2spec:containers:- image: gcr.io/tetratelabs/customers:2.0.0imagePullPolicy: Alwaysname: svcports:- containerPort: 3000 --- kind: Service apiVersion: v1 metadata:name: customerslabels:app: customers spec:selector:app: customersports:- port: 80name: httptargetPort: 3000 --- apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata:name: customers spec:hosts:- 'customers.default.svc.cluster.local'http:- route:- destination:host: customers.default.svc.cluster.localport:number: 80subset: v1 --- apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule metadata:name: customers spec:host: customers.default.svc.cluster.localsubsets:- name: v1labels:version: v1- name: v2labels:version: v2将上述 YAML 保存为 customers.yaml,用 kubectl apply -f customers.yaml 创建资源 。
为了确保一切部署和工作正常,打开 GATEWAY_URL,并确保我们从 Customers v1 获得响应 。
我们将更新 Customers 的 VirtualService,并更新流量在两个版本的 Customers 服务之间的路由 。
让我们看一下 YAML,如果请求中包含一个 header user: debug,就把流量路由到 Customers v2 。如果没有设置这个 header,我们就被路由到 Customers v1 。
apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata:name: customers spec:hosts:- 'customers.default.svc.cluster.local'http:- match:- headers:user:exact: debugroute:- destination:host: customers.default.svc.cluster.localport:number: 80subset: v2- route:- destination:host: customers.default.svc.cluster.localport:number: 80subset: v1将上述 YAML 保存为 customers-vs.yaml,然后用 kubectl apply -f customers-vs.yaml 更新 VirtualService 。
如果我们不提供端口号,VirtualService 中的目的地也会工作 。这是因为该服务只定义了一个端口 。如果我们打开
GATEWAY_URL,我们仍然应该得到来自 Customers v1的响应 。如果我们在请求中添加 header user: debug,我们会注意到customers 的响应是来自 Customers v2 。我们可以使用 ModHeader 扩展来修改浏览器中的头信息 。另外,我们也可以使用 cURL,像这样把头信息添加到请求中 。
$ curl -H "user: debug" http://GATEWAY_URL/ ... <th class="px-4 py-2">CITY</th> <th class="px-4 py-2">NAME</th> ...如果我们看一下回复,你会注意到有两栏——CITY 和 NAME 。7.2 清理删除 Deployment、Service、VirtualService、DestinationRule 和 Gateway:
kubectl delete deploy web-frontend customers-{v1,v2} kubectl delete svc customers web-frontend kubectl delete vs customers web-frontend kubectl delete dr customers kubectl delete gateway gateway
经验总结扩展阅读
- 破壁机玉米汁怎么榨才好喝
- 五行穿衣指南2023年9月24日 2023年穿衣五行颜色
- 玻璃自爆没掉下来怎么处理
- 2023年11月24日五行穿衣配色 今日幸运颜色讲究
- 2023年11月25日五行穿衣分享 穿什么颜色衣服好
- 2023年11月26日五行穿衣颜色搭配 今日招桃花幸运颜色
- 2023年11月27日五行穿衣颜色搭配 今日幸运颜色讲究
- 2023年11月28日五行穿衣配色 分享好运色穿衣搭配
- 2023年11月19日五行穿衣颜色搭配 今日幸运颜色查询
- 2023年11月20日五行穿衣查询 今日招桃花幸运颜色
