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
-
You have an ASM instance of Enterprise Edition or Ultimate Edition. For more information, see Create an ASM instance.
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
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose .
-
On the Ingress Gateway page, click the name of the target gateway.
-
On the Gateway Details page, click Advanced Options. Click the
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
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose .
-
On the Ingress Gateway page, click Create.
-
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.
-
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
-
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.
-
Create a file named httpbin.yaml with the following content.
-
Deploy the httpbin application.
kubectl apply -f httpbin.yaml -n default
Step 3: Create a VirtualService and a Gateway
-
Create a VirtualService.
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose . On the page that appears, click Create from YAML.
-
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
-
-
Create a Gateway.
-
On the details page of the ASM instance, choose in the left-side navigation pane. On the page that appears, click Create from YAML.
-
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
-
-
Verify the routing configuration.
-
Obtain the address of the ASM ingress gateway. For more information, see Create an ingress gateway.
-
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
-
Download and install the version of the lightweight stress testing tool hey that is compatible with your operating system. For more information, see hey.
-
Scale-in the ASM ingress gateway.
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose .
-
On the Ingress Gateway page, find the target gateway and click View YAML in the Actions column.
-
In the Edit dialog box, set the value of the
replicaCountparameter to 1 and click OK.
-
-
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 refusedOnly 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 responsesAll 50,000 requests returned a 200 status code, indicating that no traffic loss occurred.