istio(6):流量管理-中断访问故障注入
istio-流量管理-中断访问故障注入
移除 VirutualService 资源对象
[root@k8s-master istio-1.3.1]# kubectl delete virtualservices.networking.istio.io ratings virtualservice.networking.istio.io "ratings" deleted [root@k8s-master istio-1.3.1]# istioctl get virtualservice Command "get" is deprecated, Use `kubectl get` instead (see https://kubernetes.io/docs/tasks/tools/install-kubectl) VIRTUAL-SERVICE NAME GATEWAYS HOSTS #HTTP #TCP NAMESPACE AGE bookinfo bookinfo-gateway * 1 0 default 3d [root@k8s-master istio-1.3.1]#
然后我们查看 istio 样例文件夹下面的文件:samples/bookinfo/networking/virtual-service-ratings-test-abort.yaml 的内容
apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: ratings spec: hosts: - ratings http: - match: - headers: end-user: exact: jason fault: abort: percent: 100 httpStatus: 500 route: - destination: host: ratings subset: v1 - route: - destination: host: ratings subset: v1
通过上面的这个 yaml 文件我们可以看出这个 VirtualService 资源对象配置了在 jason 登录时,reviews 对 ratings 访问时 100% 的返回一个500
错误响应。
然后同样创建这个资源对象:(用 kubectl 或者 istioctl 工具都是可以的)
[root@k8s-master istio-1.3.1]# istioctl create -f samples/bookinfo/networking/virtual-service-ratings-test-abort.yaml Command "create" is deprecated, Use `kubectl create` instead (see https://kubernetes.io/docs/tasks/tools/install-kubectl) Error: VirtualService.networking.istio.io "ratings" is invalid: []: Invalid value: map[string]interface {}{"apiVersion":"networking.istio.io/v1alpha3", "kind":"VirtualService", "metadata":map[string]interface {}{"creationTimestamp":"2019-11-11T07:52:19Z", "generation":1, "name":"ratings", "namespace":"default", "uid":"f87d423a-2c5d-4160-ab7f-e5246a10fc8e"}, "spec":map[string]interface {}{"hosts":[]interface {}{"ratings"}, "http":[]interface {}{map[string]interface {}{"fault":map[string]interface {}{"abort":map[string]interface {}{"httpStatus":500, "percentage":map[string]interface {}{"value":100}}}, "match":[]interface {}{map[string]interface {}{"headers":map[string]interface {}{"end-user":map[string]interface {}{"exact":"jason"}}}}, "route":[]interface {}{map[string]interface {}{"destination":map[string]interface {}{"host":"ratings", "subset":"v1"}}}}, map[string]interface {}{"route":[]interface {}{map[string]interface {}{"destination":map[string]interface {}{"host":"ratings", "subset":"v1"}}}}}}}: validation failure list: spec.http.route.weight in body is required [root@k8s-master istio-1.3.1]# vim samples/bookinfo/networking/virtual-service-ratings-test-abort.yaml [root@k8s-master istio-1.3.1]# vim samples/bookinfo/networking/virtual-service-ratings-test-abort.yaml [root@k8s-master istio-1.3.1]# kubectl apply -f samples/bookinfo/networking/virtual-service-ratings-test-abort.yaml virtualservice.networking.istio.io/ratings created [root@k8s-master istio-1.3.1]# cat samples/bookinfo/networking/virtual-service-ratings-test-abort.yaml apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: ratings spec: hosts: - ratings http: - match: - headers: end-user: exact: jason fault: abort: percentage: value: 100.0 httpStatus: 500 route: - destination: host: ratings subset: v1 weight: 1 - route: - destination: host: ratings subset: v1 weight: 1
现在我们回到 BookInfo 应用,登录 jason,刷新页面,可以看到下面的现象:
我们可以看到 reviews 对 ratings 的访问失败了
其他用户都访问正常