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.
In the kubeconfig environment for your ACK cluster, run the following command to start a bash session in the sleep container:
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 following content to create a virtual service. This virtual service configures a traffic rule that retries requests to the httpbin application up to five times if a
5xxresponse is received. 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.
kubectl exec -it deployment/waypoint -- curl -XPOST "http://localhost:15000/logging?level=debug"Run the following command to view the logs of the waypoint proxy:
kubectl logs deployment/waypoint |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=25Restore the original log level.
kubectl exec -it deployment/waypoint -- curl -XPOST "http://localhost:15000/logging?level=warning"