备考ICA----Istio实验7---故障注入 Fault Injection 实验

备考ICA----Istio实验7---故障注入 Fault Injection 实验

Istio 的故障注入用于模拟应用程序中的故障现象,以测试应用程序的故障恢复能力。故障注入有两种:

1.delay延迟注入

2.abort中止注入

1. 环境准备

bash 复制代码
kubectl apply -f istio/samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f istio/samples/bookinfo/networking/bookinfo-gateway.yaml
kubectl apply -f istio/samples/bookinfo/networking/destination-rule-all.yaml
kubectl apply -f istio/samples/bookinfo/networking/virtual-service-all-v1.yaml

gateway和bookinfo.yaml详见实验1

istio/samples/bookinfo/networking/destination-rule-all.yaml

yaml 复制代码
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: productpage
spec:
  host: productpage
  subsets:
  - name: v1
    labels:
      version: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: reviews
spec:
  host: reviews
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
  - name: v3
    labels:
      version: v3
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: ratings
spec:
  host: ratings
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
  - name: v2-mysql
    labels:
      version: v2-mysql
  - name: v2-mysql-vm
    labels:
      version: v2-mysql-vm
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: details
spec:
  host: details
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2

istio/samples/bookinfo/networking/virtual-service-all-v1.yaml

yaml 复制代码
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: productpage
spec:
  hosts:
  - productpage
  http:
  - route:
    - destination:
        host: productpage
        subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: ratings
spec:
  hosts:
  - ratings
  http:
  - route:
    - destination:
        host: ratings
        subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: details
spec:
  hosts:
  - details
  http:
  - route:
    - destination:
        host: details
        subset: v1

环境确认

bash 复制代码
kubectl get dr,gw,vs,pods,svc

此时访问ingressgateway/productpage,reviews全部转给v1版本

reviews v1的版本就是没有任何☆显示

2. 部署reviews v2

当使用jason用户登录就被路由给v2版本,否则就路由给v1版本

istio/samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml

yaml 复制代码
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
    - reviews
  http:
  - match:
    - headers:
        end-user:
          exact: jason
    route:
    - destination:
        host: reviews
        subset: v2
  - route:
    - destination:
        host: reviews
        subset: v1

部署

bash 复制代码
kubectl apply -f istio/samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml

此时刷新页面任然是和刚才一样reviews任然是v1

点击右上的Sign in

此时右侧reviews就显示成v2版本

3. 注入HTTP Delay 延迟故障

当用jason用户登录,会有7秒的延迟注入

istio/samples/bookinfo/networking/virtual-service-ratings-test-delay.yaml

yaml 复制代码
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: ratings
spec:
  hosts:
  - ratings
  http:
  - match:
    - headers:
        end-user:
          exact: jason
    fault:
      delay:
        percentage:
          value: 100.0
        fixedDelay: 7s
    route:
    - destination:
        host: ratings
        subset: v1
  - route:
    - destination:
        host: ratings
        subset: v1

部署更新vs

bash 复制代码
kubectl apply -f istio/samples/bookinfo/networking/virtual-service-ratings-test-delay.yaml
  1. 用jason登录后,Bookinfo会被注入一个7秒的延迟.
  2. 右侧reviews的报错:Sorry, product reviews are currently unavailable for this book.
  3. 在 Web 浏览器中打开开发者工具菜单。打开网络选项卡。可以看到耗时为6秒多一点
  4. 因为7秒会大于3s + 1 次重试,总共 6s。结果,调用过早超时,并在 6s 后抛出错误。

    修复错误
  5. 降低注入的延迟错误到3秒以下:fixedDelay: 2s,这样1次失败加1次重试就能在6s内完成
  6. 调大reviews与ratings 的失重试次数或重试等待时间.

4. 注入 HTTP Abort 中止故障

istio/samples/bookinfo/networking/virtual-service-ratings-test-abort.yaml

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
  - route:
    - destination:
        host: ratings
        subset: v1

部署vs

bash 复制代码
kubectl apply -f istio/samples/bookinfo/networking/virtual-service-ratings-test-abort.yaml

此时继续用jason用户访问reviews就会报错:Ratings service is currently unavailable

当退出jason用户后,raviews直接路由给了v1

至此故障注入 Fault Injection 实验完成

相关推荐
无所不在的物质5 小时前
Jenkins基础教程
运维·云原生·自动化·jenkins
是芽芽哩!7 小时前
【Kubernetes 指南】基础入门——Kubernetes 基本概念(二)
云原生·容器·kubernetes
SelectDB8 小时前
Apache Doris 创始人:何为“现代化”的数据仓库?
大数据·数据库·云原生
m0_663234018 小时前
云原生是什么
云原生
运维小文10 小时前
K8S中的服务质量QOS
云原生·容器·kubernetes
华为云开发者联盟10 小时前
Karmada v1.12 版本发布!单集群应用迁移可维护性增强
云原生·kubernetes·开源·容器编排·karmada
Hadoop_Liang10 小时前
Kubernetes Secret的创建与使用
云原生·容器·kubernetes
元气满满的热码式11 小时前
K8S集群部署实战(超详细)
云原生·容器·kubernetes
秀儿y12 小时前
单机服务和微服务
java·开发语言·微服务·云原生·架构
运维&陈同学17 小时前
【Beats01】企业级日志分析系统ELK之Metricbeat与Heartbeat 监控
运维·elk·elasticsearch·云原生·kibana·heartbeat·metricbeat