測試環境版本:
> istio: 1.13.1
> kubernetes: v1.23.4
本次測試使用istio提供的httpsbin example
kubectl apply -f samples/httpbin/httpbin.yaml -n sample
retry.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: httpbin-retries
spec:
hosts:
- httpbin
http:
- route:
- destination:
host: httpbin
retries:
attempts: 3
perTryTimeout: 1s
retryOn: 5xx
部署
kubectl apply -f retry.yaml -n sample
模擬錯誤請求
kubectl run -n sample -i --rm --restart=Never dummy --image=dockerqa/curl:ubuntu-trusty --command -- curl --silent --head httpbin:8000/status/500
查看結果
kubectl logs -n sample $(kubectl get pod -n sample -l app=httpbin,version=v1 -o jsonpath={.items..metadata.name}) -c istio-proxy