When you enable compression for an ASM ingress gateway, it compresses HTTP responses. This improves response speed and reduces bandwidth usage. This topic describes how to enable compression for an ASM ingress gateway.
Prerequisites
An ingress gateway is deployed. For more information, see Create an ingress gateway.
-
If you use a domain name, it must have an Internet Content Provider (ICP) filing to be accessible.
Procedure
-
Deploy Nginx in the ACK cluster.
-
Create a file named nginx.yaml with the following content.
-
Run the following command to deploy the Nginx application.
kubectl apply -f nginx.yaml
-
-
Create a VirtualService and a Gateway.
-
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 page that appears, click Create from YAML.
-
On the Create page, select the target Namespaces, paste the following content into 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 page that appears, click Create from YAML.
-
On the Create page, select the target Namespaces, paste the following content into 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 compression for the ASM ingress gateway.
-
In the left-side navigation pane, choose .
-
On the Ingress Gateway page, find ingressgateway and click View YAML in the Actions column.
-
In the Edit dialog box, add the following content, and then click OK.
compression: content_type: - text/html enabled: true gzip: memory_level: 9 remove_accept_encoding_header: trueThe following table describes key compression fields. For more information about the compression fields, see Manage an ingress gateway by using the Kubernetes API.
Parameter
Description
compression.content_type
A list of content types to compress.
compression.enabled
Specifies whether to enable compression for the ingress gateway.
compression.gzip
The memory level for Gzip compression.
compression.remove_accept_encoding_header
-
If set to
true, the ingress gateway removes the Accept-Encoding header from a client request before forwarding it to the upstream service. -
If set to
false, the ingress gateway preserves the Accept-Encoding header in the client request before forwarding it to the upstream service.
-
-
Verify compression
-
Open your browser's developer tools. This guide uses Google Chrome as an example.
-
In the upper-right corner of Google Chrome, click the
icon. -
Select .
-
-
Access the Nginx application.
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
-
On the Services page, set Namespace to istio-system, and find the IP address of the istio-ingressgateway service (port 80) in the External IP column.
-
In your browser's address bar, enter the external IP address of the istio-ingressgateway service.
You can see that the
Content-Encodingin the response isgzip, which indicates that compression is successfully enabled for the ASM ingress gateway. In the Network panel, select any request and check the Response Headers to confirm that they containcontent-encoding: gzip. This indicates that the ASM ingress gateway has successfully enabled gzip compression.