Attach or detach SLB instances to or from scaling groups

Updated at:
Copy as MD

Attach a Classic Load Balancer (CLB) instance to a scaling group to distribute inbound traffic evenly across all ECS instances in the group. All instances—whether automatically created by Auto Scaling or manually added—serve as backend servers of the CLB instance after attachment.

Load balancer types

Alibaba Cloud provides three types of load balancers. The key operational difference is that CLB registers instances directly, while ALB and NLB route traffic to instances through target groups.

Type Layer Key characteristic References
Application Load Balancer (ALB) Layer 7 Ultra-high processing capacity with advanced content-based routing What is ALB?
Network Load Balancer (NLB) Layer 4 Ultra-high performance; supports up to 100 million concurrent connections What is NLB?
Classic Load Balancer (CLB) Layer 4 + basic Layer 7 Supports TCP, UDP, HTTP, and HTTPS; uses virtual IP addresses (VIPs) What is CLB?
Note

This topic covers CLB attachment and detachment. To attach ALB server groups to a scaling group, use AttachAlbServerGroups. To detach them, use DetachAlbServerGroups.

A CLB instance consists of three components:

Component Description
CLB instance The entity that provides load balancing by distributing traffic to backend servers. The default backend server weight is 50.
Listener Checks client requests and forwards them to backend servers, and performs health checks.
Backend server A logical group of instances that process client requests. You can use a default server group or a vServer group.

Prerequisites

Before attaching a CLB instance to a scaling group, make sure that:

  • The CLB instance is in the Running state. See Create and manage a CLB instance.

  • The CLB instance and the scaling group are in the same region.

  • The CLB instance has at least one listener in service with health check enabled. See CLB listener overview and Configure and manage CLB health checks.

  • If both the CLB instance and the scaling group use virtual private cloud (VPC) as the network type, they are in the same VPC.

  • If the CLB instance uses classic network but has VPC-based backend servers, the VPC of those backend servers matches the VPC of the scaling group.

  • The number of CLB instances you plan to attach does not exceed the quota for the scaling group. To view your quota or request an increase, visit Quota Center.

Note

In other network type combinations not listed above, the network type constraints do not apply.

Attachment and detachment behavior

ForceAttach parameter

The ForceAttach parameter controls whether existing instances in the scaling group are added to or removed from the CLB backend server group when you attach or detach a CLB instance:

Operation ForceAttach value Effect on existing instances
Attach false Existing instances are not added as backend servers
Attach true Existing instances are added as backend servers
Detach false Existing instances remain as backend servers
Detach true Existing instances are removed from backend servers

To force all existing instances to serve as backend servers when a CLB instance is already attached, call AttachLoadBalancers again with ForceAttach set to true.

You can attach or detach up to 5 CLB instances per AttachLoadBalancers or DetachLoadBalancers call.

Auto-detachment on deletion

If a CLB instance or CLB server group is deleted, scaling activities in the scaling group fail. Auto Scaling periodically scans attached CLB instances and CLB server groups and automatically detaches any that no longer exist, which prevents further scaling failures.

Detachment precaution

Before detaching a CLB instance, make sure it is no longer distributing inbound traffic to instances in the scaling group. Detaching while traffic is still flowing can cause requests to be lost.

Backend server weight rules

When scaling is triggered, the backend server weight is determined in this order:

  1. If the Weight parameter (set in the scaling group) is configured, it takes precedence.

  2. If only the Load Balancer Weight parameter (set in the scaling configuration) is configured, that value is used.

  3. If both are blank, the default weight of 50 is used.

Important

If you set Instance Configuration Source to Launch Template when creating the scaling group, configure the Weight parameter in the scaling group directly. The Load Balancer Weight parameter in the scaling configuration is not available when using launch templates.

Attach a CLB instance using the console

Attach during scaling group creation

  1. Log on to the Auto Scaling console.

  2. Log on to the Auto Scaling console.

  3. In the left-side navigation pane, click Edit Scaling Group.

  4. In the top navigation bar, select a region.

  5. Click Create.

  6. In the Create dialog box, set the Network Type parameter.

    Note

    If you set Network Type to VPC, configure the VPC parameter before configuring the Associate ALB Server Group parameter.

  7. Configure the Associate CLB Instance parameter:

    1. Select one or more CLB instances. If no CLB instances appear in the drop-down list, check that the prerequisites are met.

    2. Select one or more CLB backend server groups.

      Server group type When to use
      Default server group Receives frontend requests when no vServer group or primary/secondary server group is specified for the listener
      vServer group Use when forwarding to servers outside the default server group, or for domain name-based or URL-based routing
    3. (Optional) Configure the backend server weight.

      • Scenario 1 — Set the weight in the scaling group: 后端服务器权重

      • Scenario 2 — Set the weight in the scaling configuration: 负载均衡权重

  8. Configure any remaining parameters as needed.

  9. Click OK.

Change the CLB instance of an existing scaling group

  1. Log on to the Auto Scaling console.

  2. In the left-side navigation pane, click Edit Scaling Group.

  3. In the top navigation bar, select a region.

  4. Find the target scaling group and click Edit in the Actions column.

  5. In the Edit Scaling Group dialog box, configure the CLB synchronization behavior:

    • Select When you associate SLB instances with or disassociate SLB instances from the scaling group, existing ECS instances in the scaling group are added to or removed from the server groups of the SLB instances. to sync existing instances to the CLB backend server group automatically on attach or detach.

    • Leave it unselected to keep the backend server group unchanged regardless of attach or detach actions.

    Note

    To also update an ALB server group, select When you associate server groups with a scaling group, Auto Scaling adds instances in the scaling group to these server groups. When you disassociate server groups from a scaling group, Auto Scaling removes instances in the scaling group from these server groups.

  6. Configure the asynchronous mount behavior:

    • Select Asynchronously unmount or mount default server groups. to trigger a scaling activity each time you attach or detach the default server group. This applies only to separate attach or detach actions on the default server group.

    • Leave it unselected to attach or detach the default server group without triggering a scaling activity.

  7. (Optional) Update the Weight parameter as needed.

  8. Configure any remaining parameters as needed.

  9. Click OK.

Attach or detach CLB instances using API operations

Using API operations decouples CLB instances from scaling groups—you don't need to plan the number of load balancers when you create the scaling group, and you can adjust load balancing at any time.

Operation Description
AttachLoadBalancers Attach one or more CLB instances to a scaling group
DetachLoadBalancers Detach one or more CLB instances from a scaling group
AttachVServerGroups Attach one or more CLB server groups to a scaling group
DetachVServerGroups Detach one or more CLB server groups from a scaling group

What's next

If you attach an ApsaraDB RDS instance to a scaling group, the private IP addresses of ECS instances in the scaling group are automatically added to the ApsaraDB RDS IP address whitelist. This enables internal communication between the ECS instances and the ApsaraDB RDS instance. See Attach or detach ApsaraDB RDS instances to or from scaling groups.