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.

Prerequisites

Procedure

  1. Deploy an NGINX application in an ACK cluster.
    1. 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
    2. Run the following command to deploy an NGINX application:
      kubectl apply -f nginx.yaml
  2. Create a virtual service and an Istio gateway in an ASM instance.
    1. Log on to the ASM console.
    2. In the left-side navigation pane, choose Service Mesh > Mesh Management.
    3. 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 of the ASM instance.
    4. On the details page of the ASM instance, choose Traffic Management > VirtualService in the left-side navigation pane. On the VirtualService page, click Create.
    5. In the Create panel, select a namespace from the Namespaces drop-down list, copy the following content to the code editor, and then click OK.
      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
    6. On the details page of the ASM instance, choose Traffic Management > Gateway in the left-side navigation pane. On the Gateway page, click Create.
    7. In the Create panel, select a namespace from the Namespaces drop-down list, copy the following content to the code editor, and then click OK.
      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
  3. Enable data compression for the ingress gateway service of the ASM instance.
    1. On the details page of the ASM instance, click ASM Gateways in the left-side navigation pane.
    2. On the ASM Gateways page, find the gateway that is named ingressgateway and click YAML in the Actions column.
    3. In the Edit panel, copy the following content to the code editor and click OK.
      Note For more information about the parameters that are used for data compression, see Define a custom ingress gateway service.
      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.
      Compression-related parameters

Verify the result

  1. Open the debugging page of a browser. In this example, Google Chrome is used.
    1. Click the 设置 icon in the upper-right corner of Google Chrome.
    2. Choose More tools > Developer tools.
  2. Access the NGINX application.
    1. Log on to the ACK console.
    2. In the left-side navigation pane of the ACK console, click Clusters.
    3. 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.
    4. In the left-side navigation pane of the details page, choose Network > Services.
    5. 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.
    6. 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. Debugging page