After you enable data compression for the ingress gateway service of an Alibaba Cloud
Service Mesh (ASM) instance, the server compresses the response content for HTTP requests.
This reduces response time and traffic consumption. This topic describes how to enable
data compression for the ingress gateway service of an ASM instance.
Procedure
- Deploy an NGINX application in an ACK cluster.
- Create the nginx.yaml file.
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
sidecarset-injected: "true"
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: ClusterIP
- Run the following command to deploy an NGINX application:
kubectl apply -f nginx.yaml
- Create a virtual service and an Istio gateway in an ASM instance.
- Log on to the ASM console.
- In the left-side navigation pane, choose .
- On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM
instance or click Manage in the Actions column.
- On the details page of the ASM instance, choose in the left-side navigation pane. On the VirtualService page, click Create from YAML.
- On the Create page, select a namespace, copy the following content to the code editor,
and then click Create.
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: nginx
namespace: default
spec:
gateways:
- nginx-gateway
hosts:
- '*'
http:
- match:
- uri:
exact: /
route:
- destination:
host: nginx
port:
number: 80
- On the details page of the ASM instance, choose in the left-side navigation pane. On the Gateway page, click Create from YAML.
- On the Create page, select a namespace, copy the following content to the code editor,
and then click Create.
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: nginx-gateway
namespace: default
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- '*'
port:
name: http
number: 80
protocol: HTTP
- Enable data compression for the ingress gateway service of the ASM instance.
- On the details page of the ASM instance, click ASM Gateways in the left-side navigation pane.
- On the ASM Gateways page, find the gateway that is named ingressgateway and click YAML in the Actions column.
- In the Edit panel, copy the following content to the code editor and click OK.
compression:
content_type:
- text/html
enabled:true
gzip:
memory_level: 9
remove_accept_encoding_header: true
- compression.content_type: the Content-Type headers to be compressed.
- compression.enabled: specifies whether to enable data compression for the ingress
gateway service.
- compression.gzip: the compression format.
- compression.remove_accept_encoding_header: specifies whether to remove the Accept-Encoding
header from an HTTP request that is sent by a client before the ingress gateway service
forwards the HTTP request to an upstream server.
- If the parameter is set to
true
, the Accept-Encoding header is removed from the HTTP request.
- If the parameter is set to
false
, the Accept-Encoding header is retained in the HTTP request.

Verify the result
- Open the debugging page of a browser. In this example, Google Chrome is used.
- Click the
icon in the upper-right corner of Google Chrome.
- Choose .
- Access the NGINX application.
- Log on to the ACK console.
- In the left-side navigation pane of the ACK console, click Clusters.
- On the Clusters page, find the cluster that you want to manage and click the name of the cluster
or click Details in the Actions column. The details page of the cluster appears.
- In the left-side navigation pane of the details page, choose
- In the upper part of the Services page, select istio_system from the Namespace drop-down list. Find the ingress gateway
service that is named istio_ingressgateway and view the IP address for port 80 in
the External Endpoint column.
- On the debugging page, enter the obtained endpoint of the istio_ingressgateway service.
In the Response Headers section, the value of the
content-encoding
parameter is
gzip
, as shown in the following figure. The result indicates that data compression is
enabled for the ingress gateway service of the ASM instance.
