All Products
Search
Document Center

Alibaba Cloud Service Mesh:Enable data compression for the ingress gateway service of an ASM instance

Last Updated:Jan 23, 2024

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

  1. Deploy an NGINX application in the ACK cluster.

    1. 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
    2. Run the following command to deploy the NGINX application:

      kubectl apply -f nginx.yaml
  2. Create a virtual service and an Istio gateway.

    1. Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.

    2. 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.

    3. On the details page of the ASM instance, choose Traffic Management Center > VirtualService in the left-side navigation pane. On the page that appears, click Create from YAML.

    4. 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
    5. On the details page of the ASM instance, choose ASM Gateways > Gateway in the left-side navigation pane. On the page that appears, click Create from YAML.

    6. 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
  3. Enable data compression for the ingress gateway service of the ASM instance.

    1. On the details page of the ASM instance, choose ASM Gateways > Ingress Gateway in the left-side navigation pane.

    2. On the Ingress Gateway page, find the ingress gateway that you want to use and click YAML.

    3. 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:

      Compression

Verify that data compression is enabled for the ingress gateway service

  1. Open the debugging page of a browser. In this example, Google Chrome is used.

    1. Click the Settings icon 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. In the left-side navigation pane, click Clusters.

    2. On the Clusters page, click the name of the cluster that you want to manage and choose Network > Services in the left-side navigation pane.

    3. 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.

    4. In the DevTools panel, enter the obtained endpoint of the istio_ingressgateway service.

      If the value of the content-encoding parameter is gzip in the Response Headers section, as shown in the following figure, it indicates that data compression is enabled for the ingress gateway service. Compression