Help Center> Cloud Container Engine> User Guide> User Guide for Standard and Turbo Clusters> Network> Service> LoadBalancer> Configuring GZIP Data Compression for a LoadBalancer Service
Updated on 2024-06-26 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.

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

Using the CCE Console

  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 Creating a LoadBalancer Service.

    • 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: port used by the Service. The port number ranges from 1 to 65535.
      • Container Port: listener port of the workload. 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

        Restrictions

        Data Compression

        If this function is enabled, specific files will be compressed. If you do not enable this function, files will not be compressed.

        • 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 application, or json

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

    Figure 1 Configuring TLS

  4. Click OK.

Using kubectl

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.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 in the following format: text, xml text, plain text, css application, javascript application, x-javascript application, rss+xml application, atom+xml application, xml application, or json

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