After you enable data compression for the ingress gateway service of a 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.
Prerequisites
The cluster is added to the ASM instance. For more information, see Add a cluster to an ASM instance.
An ingress gateway is deployed. For more information, see Create an ingress gateway.
An Internet content provider (ICP) filling is obtained for a domain name if you want to use the domain name.
Procedure
Deploy an NGINX application in the ACK cluster.
Create an nginx.yaml file that contains the following content:
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 the NGINX application:
kubectl apply -f nginx.yaml
Create a virtual service and an Istio 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 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 page that appears, 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, choose in the left-side navigation pane.
On the Ingress Gateway page, find the ingress gateway that you want to use and click YAML.
In the Edit dialog box, add the following content to the YAML code and click OK.
compression: content_type: - text/html enabled: true gzip: memory_level: 9 remove_accept_encoding_header: true
The following table describes some of the fields. For more information about the fields, see Create and manage an ingress gateway by using the Kubernetes API.
Field
Description
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 and the amount of memory available for the compression.
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 forwards the HTTP request to an upstream service. 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.
Sample configuration:
Verify that data compression is enabled for the ingress gateway service
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, click Clusters.
On the Clusters page, click the name of the cluster that you want to manage and choose in the left-side navigation pane.
In the upper part of the Services page, select istio-system from the Namespace drop-down list. Find istio_ingressgateway and view the IP address whose port is 80 in the External IP column.
In the DevTools panel, enter the obtained endpoint of the istio_ingressgateway service.
If the value of the
content-encoding
parameter isgzip
in the Response Headers section, as shown in the following figure, it indicates that data compression is enabled for the ingress gateway service.