Help Center/ Cloud Container Engine/ User Guide/ Networking/ Services/ LoadBalancer/ Network and Backend Configuration/ Configuring Weights for StatefulSet Backend Pods in a LoadBalancer Service
Updated on 2026-06-16 GMT+08:00

Configuring Weights for StatefulSet Backend Pods in a LoadBalancer Service

When accessing a Service through a load balancer, traffic is typically distributed evenly across all backend pods. However, scenarios such as allocating more traffic to high-performance pods or performing grayscale releases on newly deployed pods require uneven distribution.

To support this, add the annotation kubernetes.io/elb.custom-backend-weights to the Service's metadata.annotations to configure custom weights for specific pods (StatefulSet pods only).

Prerequisites

  • A CCE Turbo cluster is available, as this function is not supported by other cluster types.
  • The cluster version must meet the following requirements:
    • v1.29: v1.29.15-r60 or later
    • v1.30: v1.30.14-r60 or later
    • v1.31: v1.31.14-r20 or later
    • v1.32: v1.32.9-r20 or later
    • v1.33: v1.33.7-r20 or later
    • v1.34: v1.34.3-r10 or later
    • v1.35: v1.35.1-r0 or later
    • Clusters of later versions

Notes and Constraints

Using kubectl

  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
    The following is an example YAML file of an ingress associated with an existing load balancer:
    apiVersion: v1
    kind: Service
    metadata:
      name: test
      labels:
        app: test-state
        version: v1
      namespace: default
      annotations:
        kubernetes.io/elb.class: performance   # Load balancer type. Only dedicated load balancers are supported.
        kubernetes.io/elb.id: <your_elb_id>   # Load balancer ID. Replace it with the actual value.
        #  Configure the weights of StatefulSet backend pods.
        kubernetes.io/elb.custom-backend-weights: |
          {
            "defaultWeight": 12,
            "groups": [
              {
                "listener": {
                  "protocol": "TCP",
                  "port": 978
                },
                "statefulSets": [
                  {
                    "name": "test-state",
                    "weights": [
                      {
                        "weight": 18,
                        "podIndexes": [1]
                      }
                    ]
                  }
                ]
              }
            ]
          }
    spec:
      selector:  # The Service must be associated with StatefulSet workloads.
        app: test-state
        version: v1
      externalTrafficPolicy: Cluster
      ports:
        - name: cce-service-0
          targetPort: 80
          nodePort: 0
          port: 978
          protocol: TCP
      type: LoadBalancer
      loadBalancerIP: 192.168.0.6
    Table 1 kubernetes.io/elb.custom-backend-weights data structure

    Parameter

    Mandatory

    Type

    Description

    defaultWeight

    Yes

    Integer

    The default backend weight. Pods without an explicitly assigned weight will use this default value.

    Value range: 1 to 100

    groups

    No

    Array of WeightGroup Object

    Weight rule groups, where each group corresponds to the backend servers attached to a listener.

    Table 2 WeightGroup data structure

    Parameter

    Mandatory

    Type

    Description

    listener

    Yes

    Listener Object

    Target listener to be matched.

    statefulSets

    Yes

    Array of StatefulSet Object

    StatefulSets for which weights are to be configured.

    Table 3 Listener data structure

    Parameter

    Mandatory

    Type

    Description

    protocol

    Yes

    String

    Listener protocol, which must match the protocol of the Service's associated listener.

    port

    Yes

    Integer

    Listener port, which must match the port on the Service's associated listener.

    Table 4 StatefulSet data structure

    Parameter

    Mandatory

    Type

    Description

    name

    Yes

    String

    StatefulSet name, which must match the name of the StatefulSet actually associated with the Service.

    If none of the workloads associated with the Service matches this name, or the matched workload is not a StatefulSet, the weight configuration is ignored.

    weights

    Yes

    Array of Weight Object

    Weights of the pods in the StatefulSet.

    Table 5 Weight data structure

    Parameter

    Mandatory

    Type

    Description

    weight

    Yes

    String

    Traffic weight allocated to a specified pod.

    Value range: 1 to 100

    podIndexes

    Yes

    Array of Integer

    List of pod indexes that use this weight. For example, [1] in the example indicates pod test-state-1.

  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 Weight Settings

  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. Switch to the Listeners tab page. Check whether a supplementary network interface is bound to the listener's backend server and whether the weight meets expectations.

Helpful Links

With cross-cluster backend servers enabled (kubernetes.io/elb.multicluster: 'true'), you can use kubernetes.io/elb.custom-backend-weights to configure weights for individual StatefulSet backend pods. For details about the applications and configurations of cross-cluster backend servers, see Configuring Multiple Cross-Cluster Backend Servers for a LoadBalancer Service. You only need to replace the kubernetes.io/elb.multicluster-loadbalancer-weight settings with the kubernetes.io/elb.custom-backend-weights settings.

The StatefulSet settings in kubernetes.io/elb.custom-backend-weights apply only to a Service's backend servers. Therefore, when using cross-cluster backend servers, configure both kubernetes.io/elb.multicluster and kubernetes.io/elb.custom-backend-weights for Services in each cluster.