All Products
Search
Document Center

Alibaba Cloud Service Mesh:Enable compression for an ASM ingress gateway

Last Updated:Jun 21, 2026

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

Procedure

  1. Deploy Nginx in the ACK cluster.

    1. Create a file named nginx.yaml with the following content.

      Nginx.yaml

      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 VirtualService and a 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 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
    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 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
  3. Enable compression for the ASM ingress gateway.

    1. In the left-side navigation pane, choose ASM Gateways > Ingress Gateway.

    2. On the Ingress Gateway page, find ingressgateway and click View YAML in the Actions column.

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

      The 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

  1. Open your browser's developer tools. This guide uses Google Chrome as an example.

    1. In the upper-right corner of Google Chrome, click the 设置 icon.

    2. Select More tools > Developer tools.

  2. Access the Nginx application.

    1. Log on to the ACK console. In the left navigation pane, click Clusters.

    2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Network > Services.

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

    4. In your browser's address bar, enter the external IP address of the istio-ingressgateway service.

      You can see that the Content-Encoding in the response is gzip, 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 contain content-encoding: gzip. This indicates that the ASM ingress gateway has successfully enabled gzip compression.