All Products
Search
Document Center

Alibaba Cloud Service Mesh:Use graceful shutdown to prevent traffic loss

Last Updated:Jun 21, 2026

When you scale-in or perform a rolling restart on an ASM ingress gateway, some gateway pods are deleted, which can cause minor traffic loss. You can enable graceful shutdown to prevent this loss by allowing existing connections to continue transmitting data for a specified period after a gateway pod is deleted.

Prerequisites

Step 1: Enable graceful shutdown

Existing gateway

Starting from ASM 1.26, changing the graceful shutdown configuration triggers a gateway restart. Perform this operation during off-peak hours to minimize impact.

Console

  1. Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.

  2. On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose ASM Gateways > Ingress Gateway.

  3. On the Ingress Gateway page, click the name of the target gateway.

  4. On the Gateway Details page, click Advanced Options. Click the Edit icon to the right of SLB graceful offline, select SLB graceful offline, configure the Connection timeout (seconds), and then click Submit.

YAML (before 1.26)

Add the serviceAnnotations annotation to the gateway YAML file.

apiVersion: istio.alibabacloud.com/v1
kind: IstioGateway
metadata:
  name: ingressgateway
  namespace: istio-system
spec:
  gatewayType: ingress
  serviceAnnotations:
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-connection-drain: 'on'          # Enables connection draining for the load balancer, which implements graceful shutdown.
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-connection-drain-timeout: '10'  # The connection draining timeout period, in seconds. Valid values: 10 to 30.
...

YAML (1.26 and later)

Add the annotations annotation to the gateway YAML file.

apiVersion: istio.alibabacloud.com/v1
kind: IstioGateway
metadata:
  annotations:
    # For CLB and NLB gateways, the valid range is [10, 890].
    # For ClusterIP and NodePort gateways, there is no upper limit.
    asm.alibabacloud.com/gateway-drain-timeout-seconds: "30"
  name: ingressgateway
  namespace: istio-system
...

New gateway

  1. Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.

  2. On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose ASM Gateways > Ingress Gateway.

  3. On the Ingress Gateway page, click Create.

  4. On the Create page, select a Cluster, set the CLB instance type to Internet Access, select a load balancer specification in the Create SLB Instance section, set Gateway instances to 10, and keep the default values for other parameters.

    For more information about the parameters, see Create an ingress gateway.

  5. Click Advanced Options, select SLB graceful offline, set Connection timeout (seconds), and then click Create.

    Parameter

    Description

    SLB graceful offline

    If this option is selected, the Classic Load Balancer (CLB) instance smoothly drains existing connections during a rolling restart of the gateway pod. This process minimizes service impact during configuration changes and gateway upgrades.

    Connection timeout (seconds)

    After the CLB instance removes the gateway pod, it waits for the configured connection timeout period before closing the connection to the pod. This parameter provides a buffer period for the gateway pod to process existing connections.

    Starting from ASM 1.26, a timeout period of up to 890 seconds is supported.

Step 2: Deploy a sample application

  1. Connect to the ACK cluster by using kubectl. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.

  2. Create a file named httpbin.yaml with the following content.

    httpbin.yaml

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: httpbin
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: httpbin
      labels:
        app: httpbin
        service: httpbin
    spec:
      ports:
      - name: http
        port: 8000
        targetPort: 80
      selector:
        app: httpbin
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: httpbin
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: httpbin
          version: v1
      template:
        metadata:
          labels:
            app: httpbin
            version: v1
        spec:
          serviceAccountName: httpbin
          containers:
          - image: docker.io/kennethreitz/httpbin
            imagePullPolicy: IfNotPresent
            name: httpbin
            ports:
            - containerPort: 80
  3. Deploy the httpbin application.

    kubectl apply -f httpbin.yaml -n default

Step 3: Create a VirtualService and a Gateway

  1. Create a VirtualService.

    1. Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.

    2. On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose Traffic Management Center > VirtualService. On the page that appears, click Create from YAML.

    3. On the Create page, select a Namespaces and a Scenario Template, paste the following YAML configuration, and then click Create.

      apiVersion: networking.istio.io/v1beta1
      kind: VirtualService
      metadata:
        name: httpbin
        namespace: default
      spec:
        gateways:
          - httpbin-gateway
        hosts:
          - '*'
        http:
          - route:
              - destination:
                  host: httpbin
                  port:
                    number: 8000
  2. Create a Gateway.

    1. On the details page of the ASM instance, choose ASM Gateways > Gateway in the left-side navigation pane. On the page that appears, click Create from YAML.

    2. On the Create page, select a Namespaces and a Scenario Template, paste the following YAML configuration, and then click Create.

      apiVersion: networking.istio.io/v1beta1
      kind: Gateway
      metadata:
        name: httpbin-gateway
        namespace: default
      spec:
        selector:
          istio: ingressgateway
        servers:
          - hosts:
              - '*'
            port:
              name: http
              number: 80
              protocol: HTTP
  3. Verify the routing configuration.

    1. Obtain the address of the ASM ingress gateway. For more information, see Create an ingress gateway.

    2. In the address bar of your browser, enter http://<ASM ingress gateway address>.

      The httpbin.org homepage appears in your browser, displaying the title httpbin.org and the description A simple HTTP Request & Response Service. This confirms that the VirtualService and Gateway are configured correctly.

Step 4: Verify the effect of graceful shutdown

  1. Download and install the version of the lightweight stress testing tool hey that is compatible with your operating system. For more information, see hey.

  2. Scale-in the ASM ingress gateway.

    1. Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.

    2. On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose ASM Gateways > Ingress Gateway.

    3. On the Ingress Gateway page, find the target gateway and click View YAML in the Actions column.

    4. In the Edit dialog box, set the value of the replicaCount parameter to 1 and click OK.

  3. Run the following command to send 50,000 requests to the httpbin application with a concurrency of 200, and compare the traffic loss before and after you enable graceful shutdown.

    hey -c 200 -n 50000 -disable-keepalive http://<ASM ingress gateway address>/

    Type

    Result analysis

    Graceful shutdown disabled

    The following output is returned:

    Status code distribution:
      [200] 49747 responses
    
    Error distribution:
      [253] Get "http://47.55.2xx.xx": dial tcp 47.55.2xx.xx:80: connect: connection refused

    Only 49,747 of the 50,000 requests returned a 200 status code, indicating that minor traffic loss occurred.

    Graceful shutdown enabled

    The following output is returned:

    ............
    Status code distribution:
      [200] 50000 responses

    All 50,000 requests returned a 200 status code, indicating that no traffic loss occurred.