ASM lets you define a retry policy for failed HTTP requests. You can specify the timeout for each retry, the number of retries, and the retry conditions. This topic describes how to configure request retries.
Preparations
Complete the required preparations and deploy the httpbin and sleep services. For more information, see Preparations.
Procedure
Verify that the service configuration is effective.
In the KubeConfig environment of your ACK cluster, run the following command to enter the sleep pod and start a bash session.
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: envoy date: Fri, 11 Aug 2023 10:03:06 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: 2
Use the following content to create a test scenario and configure a traffic rule for the httpbin application. Set the retry policy to five retries when a
5xxresponse is received. For more information, see Manage virtual services.Verify that the configuration is effective.
In the KubeConfig environment of your ACK cluster, run the following command to enter the sleep pod and start a bash session.
kubectl exec -it deploy/sleep -- shRun the following command to send a request to the httpbin service and set the response status to 500.
curl -I httpbin:8000/status/500Expected output:
HTTP/1.1 500 Internal Server Error server: envoy date: Fri, 11 Aug 2023 10:03:35 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: 382Change the log level for the sleep service to view the logs of the retry process.
Run the following command to enter the sleep pod.
kubectl exec -it {sleep-pod-name} -- shRun the following command to change the log level.
curl -XPOST http://localhost:15000/logging\?level\=debug
Run the following command to view the sleep logs.
kubectl logs {sleep-pod-name} -c istio-proxy |grep -i retryExpected output:
2023-08-14T02:11:01.896684Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C159776][S1686768772862290****] performing retry thread=36 2023-08-14T02:11:01.932148Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C159776][S1686768772862290****] performing retry thread=36 2023-08-14T02:11:02.020689Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C159776][S1686768772862290****] performing retry thread=36 2023-08-14T02:11:02.170440Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C159776][S1686768772862290****] performing retry thread=36 2023-08-14T02:11:02.275478Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C159776][S1686768772862290****] performing retry thread=36
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: httpbin