All Products
Search
Document Center

Container Compute Service:Reuse a load balancer for cross-cluster services

Last Updated:Jun 17, 2026

Cross-cluster deployments improve disaster recovery, reliability, and security isolation, but creating a LoadBalancer-type Service for each backend wastes load balancer instances. With the Cloud Controller Manager (CCM) component, you can attach both in-cluster and external endpoints to a single existing load balancer instance and configure forwarding weights for each endpoint.

Prerequisites

Use case 1: In-cluster services and external endpoints

You can attach both an in-cluster Service and external endpoints, such as ECS instances, to the same load balancer instance.

image
  1. Find the ID of your existing load balancer instance in the Classic Load Balancer (CLB) console or the Network Load Balancer (NLB) console.

  2. Reuse the existing load balancer instance when you create the Service.

    Use the console

    When you create a Service in the Container Service for Kubernetes (ACK) console, set the Service Type to LoadBalancer. Then, select Use Existing Resource, choose your existing load balancer instance, and select Create port listener.

    Use kubectl

    When you create a Service by using kubectl, add an Annotation to specify the ID of the load balancer instance.

    apiVersion: v1
    kind: Service
    metadata:
      annotations:
        service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id: ${LB_ID} # Replace ${LB_ID} with the ID of your existing load balancer instance.
        service.beta.kubernetes.io/alibaba-cloud-loadbalancer-force-override-listeners: "true"  # Set to "true" to automatically create a listener and a virtual server group.
      labels:
        #...
      name: #...
    spec:
      #...
    Important

    After you create the Service, CCM automatically creates a virtual server group and a listener in the target load balancer instance. The listener uses this virtual server group as its backend and forwards traffic to the Service port.

  3. Add the external endpoints to the automatically created virtual server group. For instructions, see Create and manage a virtual server group and NLB server groups.

    After configuration, the virtual server group shows both in-cluster Pods and external endpoints, each with a configurable forwarding weight. When an in-cluster application scales, its endpoints are automatically added to or removed from the server group without affecting external endpoints.

Use case 2: Services in multiple clusters

You can attach Services from different clusters to a single load balancer instance to provide a unified entry point.

For backend endpoints to update automatically when Pods change, all Services sharing the load balancer must also share the same listener and virtual server group. Manually create a listener and a virtual server group on the load balancer instance, then reuse them across all Services. The listener port must match the Service port.

image
Important
  • Services in different clusters must use the same port.

  • The combination of the namespace and the Service name must be unique across clusters.

  1. Create a listener and a virtual server group for the load balancer instance. For instructions, see CLB listeners, Create and manage a virtual server group, NLB listeners, and NLB server groups.

  2. Reuse the manually created virtual server group when you create the Services.

    To reuse the virtual server group, add Annotations to the Service manifest to specify the IDs of the load balancer instance and the virtual server group. You can also set a forwarding weight for the Service.

    apiVersion: v1
    kind: Service
    metadata:
      annotations:
        service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id: "${YOUR_LB_ID}" # Replace ${YOUR_LB_ID} with the ID of your existing load balancer instance.
        service.beta.kubernetes.io/alibaba-cloud-loadbalancer-vgroup-port: "${YOUR_VGROUP_ID}:{PORT}" # Replace ${YOUR_VGROUP_ID} with the ID of the virtual server group and {PORT} with the port of the Service.
        service.beta.kubernetes.io/alibaba-cloud-loadbalancer-weight: "100" # Optional. The forwarding weight for Pods belonging to this Service. Valid values range from 1 to 1000. The default is 100.
      labels:
        #...
      name: #...
    spec:
      #...
    Note

    If you have multiple port and virtual server group combinations for service.beta.kubernetes.io/alibaba-cloud-loadbalancer-vgroup-port, separate them with a comma (,). For example: "${YOUR_VGROUP_ID_1}:80, ${YOUR_VGROUP_ID_2}:443".

    After configuration, you can view Pods from Services in different clusters in the virtual server group on the load balancer console. When an application in one cluster scales, the CCM automatically adds or removes its Pods from the server group without affecting Pods from other clusters.

    Important

    If you configure the forwarding weight by using an Annotation in the Service manifest, do not adjust the weight in the console, as this can cause state inconsistencies.

Related documents