All Products
Search
Document Center

Alibaba Cloud Service Mesh:Retry requests

Last Updated:Dec 01, 2025

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

  1. Check whether the service configurations take effect.

    1. 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 -- sh
    2. Run the following command to send a request to the HTTPBin service:

      curl -I httpbin:8000/status/500

      Expected 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
  2. 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 5xx response 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: httpbin
  3. Check whether the configurations take effect.

    1. 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 -- sh
    2. Run the following command to send a request to the HTTPBin service:

      curl -I httpbin:8000/status/500

      Expected 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: 329
    3. Change 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"
    4. Run the following command to view the logs of the waypoint proxy:

      kubectl logs deployment/waypoint |grep -i retry

      Expected 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
    5. Restore the original log level.

      kubectl exec -it deployment/waypoint -- curl -XPOST "http://localhost:15000/logging?level=warning"