5.3.5 设置请求超时

1.前置条件

  • 安装好istio
  • 部署bookinfo示例并应用默认目标规则

    kubectl apply -f samples/bookinfo/networking/destination-rule-all-mtls.yaml
    
  • 初始化应用到版本路由到v1

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

2.请求超时

HTTP请求的超时可以用路由规则的timeout字段来指定。默认情况下,超时是禁用的,本任务中,会把reviews服务的超时设置为1秒。 为了观察效果,还需要在对ratings服务的调用上人为引入2秒的延迟。

1.将请求路由到reviews服务的v2版本

kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
    - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v2
EOF
virtualservice.networking.istio.io/reviews configured

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

kubectl apply -f - <<EOF
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
EOF
virtualservice.networking.istio.io/ratings configured

3.打开bookinfo页面http://${GATEWAY_URL}/productpage

这时可以看到Bookinfo应用运行正常(显示了评级的星型符号),但是每次刷新页面,都会有2秒的延迟。

image-20200213100008539

4.对reviews服务的调用增加一个半秒的请求超时

kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
  - reviews
  http:
  - route:
    - destination:
        host: reviews
        subset: v2
    timeout: 0.5s
EOF
virtualservice.networking.istio.io/reviews configured

5.刷新Bookinfo页面。

这时候应该看到1秒钟就会返回,而不是之前的2秒钟,但reviews是不可用的。

image-20200213161836819

Sorry, product reviews are currently unavailable for this book.

Copyright © huangzhongde.cn 2021 all right reserved,powered by Gitbook该文件修订时间: 2022-01-28 00:02:24

results matching ""

    No results matching ""