跳到主要内容

VS故障注入

1.VirtualService故障注入介绍

故障注入在vs的fault字段定义。

1.1.abort: 中断故障注入

percentage: 故障百分比--在value里指定具体数值,用于指定故障百分比,比如写100的话,则是所有访问都是故障

httpStatus:模拟错误,返回的错误代码

1.2.delay: 延迟故障注入

percentage: 故障百分比--在value里指定具体数值,用于指定故障百分比,比如写100的话,则是所有访问都是故障

fixedDelay:用于设置延迟多久回应

2.配置

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myvs2
spec:
hosts:
- "bb.xiebo.pro"
gateways:
- mygw
http:
- fault:
#延时
#delay:
# percent: 100
# fixedDelay: 1s
#中断
abort:
percentage:
value: 100
httpStatus: 503
route:
- destination:
host: svc2

3.响应超时设置

apiVersion: networking.istio.io/v1alpha3 
kind: VirtualService
metadata:
name: myvs1
spec:
hosts:
- "aa.xiebo.pro"
gateways:
- mygw
http:
- route:
- destination:
host: svc1
timeout: 1s

4.失败重试

apiVersion: networking.istio.io/v1alpha3 
kind: VirtualService
metadata:
name: myvs1
spec:
hosts:
- "aa.xiebo.pro"
gateways:
- mygw
http:
- route:
- destination:
host: svc1
timeout: 1s
retries:
#重试次数
attempts: 3
#重试超时时间
perTryTimeout: 10s
#重试触发状态码
retryOn: 5xx

5.流量镜像

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myvs
spec:
hosts:
- "aa.xiebo.pro"
gateways:
- mygw
http:
- route:
- destination:
host: svc1
mirror:
host: svc2