Help Center/ Cloud Container Engine/ User Guide/ Networking/ Services/ LoadBalancer/ Configuring GZIP Data Compression for a LoadBalancer Service
Updated on 2025-08-19 GMT+08:00

Configuring GZIP Data Compression for a LoadBalancer Service

LoadBalancer Services support data compression, which reduces the size of files to be transferred, improves file transfer efficiency, and reduces the bandwidth needed for the transmission.

  • This function relies on ELB capabilities. Before using this function, check whether it is supported in the current region. For details about the regions where this function is supported, see Elastic Load Balance Function Overview.
  • After data compression is configured, if you delete the data compression configuration on the CCE console or delete the target annotation from the YAML file, the configuration on the ELB will be retained.

Prerequisites

  • A Kubernetes cluster is available and the cluster version meets the following requirements:
    • v1.23: v1.23.14-r0 or later
    • v1.25: v1.25.9-r0 or later
    • v1.27: v1.27.6-r0 or later
    • v1.28: v1.28.4-r0 or later
    • Other clusters of later versions

Creating a LoadBalancer Service and Configuring GZIP Data Compression

  1. Log in to the CCE console and click the cluster name to access the cluster console.
  2. In the navigation pane, choose Services & Ingresses. In the upper right corner, click Create Service.
  3. Configure Service parameters. In this example, only mandatory parameters are listed. For details about how to configure other parameters, see Using the CCE Console.

    • Service Name: Specify a Service name, which can be the same as the workload name.
    • Service Type: Select LoadBalancer.
    • Selector: Add a label and click Confirm. The Service will use this label to select pods. You can also click Reference Workload Label to use the label of an existing workload. In the dialog box that is displayed, select a workload and click OK.
    • Load Balancer: Select a load balancer type and creation mode.
      • In this example, only dedicated load balancers are supported, and the type of the load balancer must be Application (HTTP/HTTPS) or Network (TCP/UDP/TLS) & Application (HTTP/HTTPS). Otherwise, HTTP or HTTPS cannot be enabled on the listener port.
      • This section uses an existing load balancer as an example. For details about the parameters for automatically creating a load balancer, see Table 1.
    • Ports
      • Protocol: Select TCP. If you select UDP, HTTP and HTTPS will be unavailable.
      • Service Port: the port used by the Service. The port number ranges from 1 to 65535.
      • Container Port: the port that the workload listens on. For example, Nginx uses port 80 by default.
      • Frontend Protocol: In this example, select HTTP or HTTPS for the Service.
    • Listener
      • Advanced Options: Select a proper option.

        Configuration

        Description

        Constraint

        Data Compression

        If this function is enabled, specific files will be compressed. If it is not enabled, files will remain uncompressed.

        • Brotli can compress all file formats.
        • GZIP can compress the files in the following format:

          text/xml, text/plain, text/css, application/javascript, application/x-javascript, application/rss+xml, application/atom+xml, application/xml, and application/json

        This parameter is available only after HTTP/HTTPS is enabled on the listener port of a dedicated load balancer.

    Figure 1 Configuring data compression

  4. Click Create.
This section uses an existing load balancer as an example. An example YAML file of a Service with data compression enabled is as follows:
apiVersion: v1
kind: Service
metadata:
  name: test
  labels:
    app: nginx
  namespace: default
  annotations:
    kubernetes.io/elb.class: performance                              # Load balancer type, which can only be performance (dedicated load balancer)
    kubernetes.io/elb.id: 35cb350b-23e6-4551-ac77-10d5298f5204        # ID of an existing load balancer
    kubernetes.io/elb.protocol-port: http:80                          # The HTTP port 80 is used.
    kubernetes.io/elb.gzip-enabled: 'true'                            # Enable data compression.
spec:
  selector:
    app: nginx
  externalTrafficPolicy: Cluster
  ports:
    - name: cce-service-0
      targetPort: 80
      nodePort: 0
      port: 80
      protocol: TCP
  type: LoadBalancer
  loadBalancerIP: **.**.**.**    # IP address of the load balancer
Table 1 Key parameters

Parameter

Type

Description

kubernetes.io/elb.gzip-enabled

String

  • true: Data compression is enabled, and specific file types will be compressed.
  • false: Data compression is disabled, and no files will be compressed. By default, data compression is disabled.

The files in the following format can be compressed:

  • Brotli can compress all file formats.
  • GZIP can compress the files of the following types: text/xml, text/plain, text/css, application/javascript, application/x-javascript, application/rss+xml, application/atom+xml, application/xml, and application/json

This function is available only for HTTP/HTTPS listeners of dedicated load balancers.

Verifying Configuration

  1. Log in to the CCE console and click the cluster name to access the cluster console.
  2. In the navigation pane, choose Services & Ingresses. Locate the row that contains the created Service and click the load balancer name to go to the ELB console.
  3. Switch to the Listeners tab, click the listener name of the created port, and check whether the option is enabled.