本文的目的:超时和故障注入。
继# 【玩转服务网格】如何使用网格进行灰度发布中的实例继续验证超时和故障注入机制。
超时
更新VirtualService信息,对v2版本的请求增加1s的timeout(实例服务是200ms到2s的随机延时返回)。
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: canary
spec:
hosts:
- canary
http:
- match:
- headers:
user:
exact: jesse
route:
- destination:
host: canary
subset: v2
### if upstream server response delay is greater than 1s, send timeout error to client
timeout: 1s
- route:
- destination:
host: canary
subset: v1
查看客户端sidecar的route信息,已经下发生效。istioctl pc route -n canary toolbox-78555898fb-ntsc4 --name 80 -ojson
发送请求测试timeout机制。可以看到服务端耗时1583ms,导致了客户端请求1s超时,验证通过。
注入错误
模拟一定概率的请求出错,进行混沌测试。
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: canary
spec:
hosts:
- canary
http:
- match:
- headers:
user:
exact: jesse
route:
- destination:
host: canary
subset: v2
### send 500 to client in 80%
fault:
abort:
httpStatus: 500
percentage:
value: 80
- route:
- destination:
host: canary
subset: v1
查看配置已下发。
客户端请求,有一定概率请求为500错误。
[root@toolbox-78555898fb-ntsc4 /]# curl -I canary/hello -H "user: jesse"
HTTP/1.1 500 Internal Server Error
content-length: 18
content-type: text/plain
date: Mon, 02 Jan 2023 13:50:47 GMT
server: envoy