You can define the retry policy to be used when an HTTP request fails, such as the timeout for each retry attempt, the number of retries, and the retry conditions. This topic describes how to configure a retry policy.
Prerequisites
The preparations are completed, and the HTTPBin and sleep services are deployed. For more information, see Preparations.
Procedure
Check whether the service configurations take effect.
Use kubectl to connect to the Container Service for Kubernetes (ACK) cluster based on the information in the kubeconfig file, and then run the following command to enable bash for the sleep service:
kubectl exec -it deploy/sleep -- shRun the following command to send a request to the HTTPBin service:
curl -I httpbin:8000/status/500Expected output:
HTTP/1.1 500 INTERNAL SERVER ERROR Server: gunicorn/19.9.0 Date: Tue, 29 Aug 2023 02:36:24 GMT Connection: keep-alive Content-Type: text/html; charset=utf-8 Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true Content-Length: 0
Use the istioctl tool to run the following command to deploy a Layer 7 waypoint proxy for the HTTPBin service:
istioctl x waypoint apply --service-account httpbinUse the following content to create a virtual service for testing, and configure a traffic rule for the HTTPBin service. The retry policy is to retry a request five times if the response is
5xx. For more information, see Manage virtual services.apiVersion: networking.istio.io/v1beta1 kind: VirtualService metadata: name: httpbin-vs namespace: default spec: hosts: - httpbin http: - retries: attempts: 5 retryOn: 5xx route: - destination: host: httpbinCheck whether the configurations take effect.
Use kubectl to connect to the ACK cluster based on the information in the kubeconfig file, and then run the following command to enable bash for the sleep service:
kubectl exec -it deploy/sleep -- shRun the following command to send a request to the HTTPBin service:
curl -I httpbin:8000/status/500Expected output:
HTTP/1.1 500 Internal Server Error server: istio-envoy date: Fri, 11 Aug 2023 07:00:19 GMT content-type: text/html; charset=utf-8 access-control-allow-origin: * access-control-allow-credentials: true content-length: 0 x-envoy-upstream-service-time: 329Change the log level of the waypoint proxy to view the logs of the retry process.
Run the following command to access the httpbin-istio-waypoint pod:
kubectl exec -it {Name of the httpbin-istio-waypoint pod} -- shRun the following command to change the log level of the waypoint proxy:
curl -XPOST http://localhost:15000/logging\?level\=debug
Run the following command to view the logs of the waypoint proxy:
kubectl logs {Name of the httpbin-istio-waypoint pod} | grep -i retryExpected output:
2023-08-11T07:00:19.512883Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C1080][S1651638534493129****] performing retry thread=25 2023-08-11T07:00:19.516388Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C1080][S1651638534493129****] performing retry thread=25 2023-08-11T07:00:19.547553Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C1080][S1651638534493129****] performing retry thread=25 2023-08-11T07:00:19.633248Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C1080][S1651638534493129****] performing retry thread=25 2023-08-11T07:00:19.829611Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C1080][S1651638534493129****] performing retry thread=25