备考ICA----Istio实验8—请求超时 Request Timeouts 实验

1. 重置bookinfo环境

kubectl delete all --all --now
kubectl delete dr --all
kubectl delete vs --all
kubectl delete gw --all
kubectl apply -f istio/samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f istio/samples/bookinfo/networking/bookinfo-gateway.yaml

将环境恢复到刷新随机到3个不同版本的reviews上
v1
备考ICA----Istio实验8---请求超时 Request Timeouts 实验-LMLPHP
v2
备考ICA----Istio实验8---请求超时 Request Timeouts 实验-LMLPHP
v3
备考ICA----Istio实验8---请求超时 Request Timeouts 实验-LMLPHP
流量随机分配到3个版本
备考ICA----Istio实验8---请求超时 Request Timeouts 实验-LMLPHP

2. 通过subnet进行流量调度

2.1 给3个版本都打上subnet子集标签

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

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

部署使它生效

kubectl apply -f istio/samples/bookinfo/networking
/destination-rule-all.yam

此时任然是随机在3个版本上调度

2.2 通过subnet将所有流量调度到v1

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

2.3 将所有流量调度给v2并加入2秒延迟

2.3.1 所有流量调度到v2

timeout/timeout-vs-reviews.yaml

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v2

部署yaml

kubectl apply -f timeout/timeout-vs-reviews.yaml

此时不管如何刷新都是到v2版本
备考ICA----Istio实验8---请求超时 Request Timeouts 实验-LMLPHP

2.3.2 对 ratings 服务的调用添加 2 秒延迟 ratings

timeout/timeout-vs-ratings.yaml

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: ratings
spec:
  hosts:
  - ratings
  http:
  - fault:
      delay:
        percent: 100
        fixedDelay: 2s
    route:
    - destination:
        host: ratings
        subset: v1

部署生效

kubectl apply -f timeout/timeout-vs-ratings.yaml

部署后v2任然能被正确访问,但会有2s的延迟
备考ICA----Istio实验8---请求超时 Request Timeouts 实验-LMLPHP

2.3.3 将reviews的超时时间改为0.5s

timeout/timeout-vs-reviews-05.yaml

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v2
    timeout: 0.5s

部署生效

kubectl apply -f timeout/timeout-vs-reviews-05.yaml

由于reviews的超时时间为0.5s,当遇到rating 2秒等待,在1次超时1次重试后就出现以下报错: Sorry, product reviews are currently unavailable for this book.
备考ICA----Istio实验8---请求超时 Request Timeouts 实验-LMLPHP

2.3.4 将reviews的超时时间设置为2.5秒

timeout/timeout-vs-reviews-25.yaml

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v2
    timeout: 2.5s

配置生效

kubectl apply -f timeout/timeout-vs-reviews-25.yaml

只要把timeout调到2以上即可2秒延迟,浏览v2版本
reviews如果timeout值小于等于rating的延迟,则无法正常访问到reviews内容.
备考ICA----Istio实验8---请求超时 Request Timeouts 实验-LMLPHP
至此,请求超时 Request Timeouts 实验

03-28 12:58