Server Load Balancer (SLB) is a service that forwards network traffic to backend servers to increase the throughput of your applications. You can use SLB to prevent service interruptions that are caused by single points of failure (SPOFs) and improve the availability of applications. This topic describes how to add elastic container instances as backend servers to an SLB instance. This topic also describes how to configure listeners for the SLB instance to forward traffic to the elastic container instances.
Background information
An SLB service consists of an SLB instance, listeners, and backend servers. The following procedure describes how to add elastic container instances to an SLB instance:
Create multiple elastic container instances.
Before you build an SLB service, you must specify a region and a network based on your business requirements. Then, you must create elastic container instances in the region to deploy your applications.
Create an SLB instance.
Before you build an SLB service, you must create an SLB instance. Each SLB instance is a service entity that receives network traffic and forwards the traffic to backend servers.
The SLB service is categorized into multiple types. You can select an SLB type based on your business requirements. For more information What is SLB?
Add elastic container instances as backend servers to the SLB instance.
Backend servers are a group of servers that receive frontend requests. After you add elastic container instances as backend servers to an SLB instance, the elastic container instances can receive client requests that are forwarded by the SLB instance. For Application Load Balancer (ALB) and Network Load Balancer (NLB) instances, you must create a server group before you can add elastic container instances to ALB and NLB instances. For Classic Load Balancer (CLB) instances, you can directly add elastic container instances to the default server group.
Configure listeners.
A listener checks client requests and forwards healthy client requests to backend servers. You must configure listeners for your SLB instance. A listener includes a protocol, port, and scheduling algorithms.
Preparations
Create multiple elastic container instances.
In this example, two elastic container instances that run on the NGINX image are created. When you create the elastic container instances, enable the logging feature. For more information, see Use an NGINX image to create an elastic container instance.

Create a CLB instance.
A CLB instance that supports Internet access is created. For more information, see Create a CLB instance.
NoteThis topic describes how to configure CLB for elastic container instances. You can follow the same procedure to configure ALB or NLB for elastic container instances.

Procedure
After you add elastic container instances as backend servers to a CLB instance and configure listeners for the CLB instance, the CLB instance can forward requests from clients to the elastic container instances.
Elastic container instances that are in a final state such as the Succeeded or Failed state cannot be added as backend servers to an SLB instance.
The Elastic Container Instance console
Log on to the SLB console. In the left-side navigation pane, choose CLB > Instances.
On the Instances page, find the CLB instance that you want to manage and click Add Backend Server in the Actions column.
In the Servers panel, add elastic container instances as backend servers to the CLB instance.
Set Backend Server Type to ECI, select multiple elastic container instances, and then click Next.
Set weights for the elastic container instances and then click Add.
The default weight is 100. A larger weight indicates that the backend server can receive more requests.
Click OK. In the message that appears, click OK.
On the Default Server Group tab of the CLB instance, you can view the elastic container instances that you added.
On the Instances page, find the CLB instance that you want to manage and click Configure Listener in the Actions column.
In the Protocol & Listener step, configure listeners for the CLB instance and then click Next.
Select a listener protocol and port based on your requirements. Examples:
Listener protocol: TCP
Listener port: 80
Use the default values for other parameters.
In the Backend Servers step, configure the backend servers and then click Next.
If you set Server Group Type to Default Server Group, the elastic container instances that you added in step 3 are displayed in the Selected Servers list. Set a listener port for the servers based on your requirements. In this example, set the listener port of the elastic container instances to 80.
In the Health Check step, retain the default settings and click Next.
In the Confirm step, check the configurations and then click Submit.
OpenAPI
Call the DescribeContainerGroups API operation of Elastic Container Instance to query information about the elastic container instances.
Obtain and record the following information about the elastic container instances from the response:
The IDs of the elastic container instances, which are indicated by the ContainerGroupId response parameter.
The internal IP addresses of the elastic container instances, which are indicated by the IntranetIp parameter.
Call the AddBackendServers API operation of CLB to add backend servers.
The following table describes the main request parameters.
Parameter
Type
Example
Description
LoadBalancerId
String
lb-2ze7o5h52g02kkzz******
The ID of the CLB instance.
BackendServers
String
[{ "ServerId": "eci-2zeb9fwsn3n5lano****", "Weight": "100", "Type": "eci", "ServerIp": "172.16.12.**", "Port":"80","Description":"test" },{ "ServerId": "eci-2zeb9fwsn3n5lano****", "Weight": "100", "Type": "eci", "ServerIp": "172.16.12.**", "Port":"80","Description":"test" }]
The backend servers that you want to add to the CLB instance. Configure the following parameters:
ServerId: the ID of the backend server. Enter the ID of the elastic container instance.
Weight: the weight of the backend server. Valid values: 0 to 100. Default value: 100. A value of 0 indicates no requests are forwarded to the backend server.
Description: the description of the backend server.
Type: the type of the backend server. Set the value to
eci.ServerIp: the internal IP address of the backend server. In this example, enter the internal IP address of the elastic container instance.
Port: the backend port that receives requests.
Call one of the following listener-related API operations of CLB to create a listener:
CreateLoadBalancerTCPListener: creates a listener that uses the TCP protocol
CreateLoadBalancerUDPListener: creates a listener that uses the UDP protocol
CreateLoadBalancerHTTPListener: creates a listener that uses the HTTP protocol
CreateLoadBalancerHTTPSListener: creates a listener that uses the HTTPS protocol
In this example, a listener that uses the TCP protocol is created. The following table describes the parameters.
Parameter
Type
Example
Description
Bandwidth
Integer
-1
The maximum bandwidth of the listener. Valid values:
-1: For a pay-by-traffic Internet-facing CLB instance, set the value to -1. This value indicates that the bandwidth is unlimited.
1 to 5120: For a pay-by-bandwidth Internet-facing CLB instance, you can specify the maximum bandwidth of each listener. The sum of the maximum bandwidth values of all listeners cannot exceed the maximum bandwidth of the CLB instance. Unit: Mbit/s.
BackendServerPort
Integer
80
The backend port of the CLB instance.
Valid values: 1 to 65535.
LoadBalancerId
String
lb-2ze7o5h52g02kkzz******
The ID of the CLB instance.
ListenerPort
Integer
80
The frontend port of the CLB instance.
Valid values: 1 to 65535.
Call the StartLoadBalancerListener API operation of CLB to start the listeners.
Verify the result
Run the following command multiple times to send requests to the public IP address of the CLB instance:
curl 39.106.**.** 80View the logs of the elastic container instances. The logs show that the CLB instance forwards the requests to different elastic container instances.