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
- To create a cluster using commands, ensure kubectl is used. For details, see Accessing a Cluster Using kubectl.
Creating a LoadBalancer Service and Configuring GZIP Data Compression
- Log in to the CCE console and click the cluster name to access the cluster console.
- In the navigation pane, choose Services & Ingresses. In the upper right corner, click Create Service.
- 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.
This parameter is available only after HTTP/HTTPS is enabled on the listener port of a dedicated load balancer.
- Advanced Options: Select a proper option.
Figure 1 Configuring data compression - Click Create.
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
Parameter |
Type |
Description |
---|---|---|
kubernetes.io/elb.gzip-enabled |
String |
The files in the following format can be compressed:
This function is available only for HTTP/HTTPS listeners of dedicated load balancers. |
Verifying Configuration
- Log in to the CCE console and click the cluster name to access the cluster console.
- 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.
- Switch to the Listeners tab, click the listener name of the created port, and check whether the option is enabled.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot