Help Center/ Cloud Container Engine/ User Guide/ Networking/ Services/ LoadBalancer/ Protocol and Listening Configuration/ Configuring a Range of Listening Ports for LoadBalancer Services
Updated on 2026-06-16 GMT+08:00

Configuring a Range of Listening Ports for LoadBalancer Services

When creating a LoadBalancer Service, you can specify a port range for the ELB listener. This allows the listener to receive requests on ports within the specified range and forward them to the target backend servers.

This function requires ELB. Before using this function, check whether ELB supports full-port listening and forwarding for layer-4 protocols in the current region.

Prerequisites

  • A Kubernetes cluster is available and the cluster version meets the following requirements:
    • v1.23: v1.23.18-r0 or later
    • v1.25: v1.25.13-r0 or later
    • v1.27: v1.27.10-r0 or later
    • v1.28: v1.28.8-r0 or later
    • v1.29: v1.29.4-r0 or later
    • v1.30: v1.30.1-r0 or later
  • To create a cluster using commands, ensure kubectl is used. For details, see Accessing a Cluster Using kubectl.

Precautions

  • Listening port ranges can be configured only when you use a dedicated load balancer with TCP, UDP, or TLS.
  • ELB listeners do not support direct port modification. When a Service's port range changes, CCE deletes the original listener and creates a new one. This causes a brief service interruption (typically a few seconds) during listener rebuild. Evaluate the impact before changing Service ports and proceed with caution.

Creating a LoadBalancer Service and Configuring a Range of Listening Ports

Use one of the following methods.

  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.

    In this example, only mandatory parameters for configuring SNI are listed. Retain the default settings for other parameters. For details, see Using the CCE Console (New Version).

  3. Configure basic parameters.

    Parameter

    Description

    Example

    Service Type

    Select LoadBalancer.

    None

    Service Name

    Enter a name, which can be the same as the workload name.

    nginx

    Namespace

    Select the namespace that the workload belongs to.

    default

    Selector

    Add the key and value of a pod label. The Service will be associated with the workload pods based on the label and direct traffic to the pods with this label.

    You can also click Reference Workload Label to use the label of an existing workload. In the dialog box displayed, select a workload and click OK.

    app:nginx

  4. Configure load balancer parameters.

    Parameter

    Description

    Example

    Load Balancer

    Select a load balance type and how the load balancer will be created.
    • Use existing: Only the load balancers in the same VPC as the cluster can be selected. If no load balancer is available, click Create Load Balancer to create one on the ELB console.
    • Auto create: The load balancer will be created in the VPC that the cluster belongs to. For details, see Table 1.

    An existing Dedicated load balancer of the Network (TCP/UDP/TLS) & Application (HTTP/HTTPS) type

  5. Configure access parameters.

    Parameter

    Description

    Example

    Service Affinity

    Whether to route external traffic to a local node or a cluster-wide endpoint. For details, see Service Affinity (externalTrafficPolicy).
    • Cluster-level: The IP addresses and ports of all nodes in a cluster can access the workload associated with the Service. However, accessing the Service may result in performance deterioration due to route redirection, and the client's source IP address may not be obtainable.
    • Node-level: Only the IP address and port of the node where the workload is located can access the workload associated with the Service. Accessing the Service will not result in a performance decrease due to route redirection, and the client's source IP address can be obtained.

    Cluster-level

    Port

    • Protocol: the protocol used by the Service. According to the Kubernetes implementation, if a Service uses a load balancer with a non-UDP protocol, this parameter must be set to TCP and the corresponding listener frontend protocol must be selected. For details, see Protocols for Services.
    • Container Port: the port that the workload listens on. For example, Nginx uses port 80 by default.
    • Service Port: the port used by the Service.
      • Listen on a port: The port ranges from 1 to 65535.
      • Listen on ports: ELB allows you to create listeners that listen on ports within specified ranges. Each listener can support up to 10 non-overlapping port ranges.

        To configure port ranges for load balancer listeners, ensure the following conditions are met:

        • The cluster version must be v1.23.18-r0, v1.25.13-r0, v1.27.10-r0, v1.28.8-r0, v1.29.4-r0, v1.30.1-r0, or later.
        • A dedicated load balancer must be used with TCP/UDP/TLS selected.
        • This function requires ELB. Before using this function, check whether ELB supports full-port listening and forwarding for layer-4 protocols in the current region.
    • Frontend Protocol: Set the protocol of the load balancer listener for establishing connections with clients. When a dedicated load balancer is selected, HTTP/HTTPS can be configured only when Application (HTTP/HTTPS) is selected, and TLS can be configured only when Network (TCP/UDP/TLS) is selected.
    NOTE:

    When a LoadBalancer Service is created, a random node port number (NodePort) is automatically generated.

    • Protocol: TCP
    • Container Port: 80
    • Service Port: 80-88
    • Frontend Protocol: TCP

  6. Click Create.
  1. Log in to the CCE console and click the cluster name to access the cluster console.
  2. Choose Services and Ingresses in the navigation pane, click the Services tab, and click Create Service in the upper right corner.
  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 (Old Version).

    • 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.
      • This section uses an existing load balancer as an example. For details about the parameters for automatically creating a load balancer, see Table 4.
    • Port
      • Protocol: Select TCP or UDP.
      • Container Port: the port that the workload listens on. For example, Nginx uses port 80 by default.
      • Service Port: the port used by the Service. In this example, select Listen on ports and configure a port range. All the requests received on the ports within this range will be forwarded to the backend server. Configure the port range from 1 to 65535. You can add a maximum of 10 non-overlapping ranges of listening ports.
      • Frontend Protocol: For a dedicated load balancer, to use TLS, the type of the load balancer must be Network (TCP/UDP/TLS).
    Figure 1 Configuring listening port ranges

  4. Click OK.
  1. Use kubectl to access the cluster. For details, see Accessing a Cluster Using kubectl.
  2. Create a YAML file named service-test.yaml. The file name can be customized.

    vi service-test.yaml
    An example YAML file of a Service associated with an existing load balancer is as follows:
    apiVersion: v1
    kind: Service
    metadata:
      name: service-test
      labels:
        app: test
        version: v1
      namespace: default
      annotations:
        kubernetes.io/elb.class: performance  # A dedicated load balancer is required.
        kubernetes.io/elb.id: <your_elb_id>  # Replace it with the ID of your existing load balancer.
        kubernetes.io/elb.port-ranges: '{"cce-service-0":["100,200", "300,400"], "cce-service-1":["500,600", "700,800"]}'  # Configure ranges of listening ports.
    spec:
      selector:
        app: test
        version: v1
      externalTrafficPolicy: Cluster
      ports:
        - name: cce-service-0
          targetPort: 80          # Replace it with your container port.
          nodePort: 0
          port: 100       # If a port range is configured for listening, this parameter becomes invalid. However, it still needs to be assigned a unique value. By default, it is set to the starting port number of the range.
          protocol: TCP  
        - name: cce-service-1
          targetPort: 81          # Replace it with your container port.
          nodePort: 0
          port: 500       # If a port range is configured for listening, this parameter becomes invalid. However, it still needs to be assigned a unique value.
          protocol: TCP  
      type: LoadBalancer
      loadBalancerIP: <your_elb_ip>  # Replace it with the private IP address of your existing load balancer.
    Table 1 Parameters for listening to ports within a range

    Parameter

    Mandatory

    Type

    Description

    kubernetes.io/elb.port-ranges

    Yes

    String

    If a dedicated load balancer is used and the TCP, UDP, or TLS protocol is selected, you can create a listener that listens to ports within a certain range from 1 to 65535. You can add a maximum of 10 port ranges that do not overlap for each listener.

    The parameter value is in the following format, where ports_name and port must be unique:

     '{"<ports_name_1>":["<port_1>,<port_2>","<port_3>,<port_4>"], "<ports_name_2>":["<port_5>,<port_6>","<port_7>,<port_8>"]}'

    For example, the port names are cce-service-0 and cce-service-1, and the listener listens to ports 100–200 and 300–400, and 500–600 and 700–800, respectively.

    '{"cce-service-0":["100,200", "300,400"], "cce-service-1":["500,600", "700,800"]}'

  3. Create the Service.

    kubectl create -f service-test.yaml

    If information similar to the following is displayed, the Service has been created:

    service/service-test created

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 and Ingresses. Locate the row that contains the created Service and click the load balancer name to go to the ELB console.
  3. On the Listeners tab page, check the port number of the new listener.