All Products
Search
Document Center

Add elastic container instances to an SLB instance

Last Updated: Nov 09, 2021

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 to forward Internet traffic to the elastic container instances.

Background information

An SLB service consists of an SLB instance, listeners, and backend servers. The following section describes how to configure elastic container instances and add the elastic container instances to an SLB instance:

  1. 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, create elastic container instances in the region to deploy your applications.

  2. 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 Classic Load Balancer (CLB) and Application Load Balancer (ALB). You can select an SLB type based on your business requirements. For information about the differences between CLB and ALB, see SLB instance family.

  3. 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 ALB instances, you must create a server group before you can add elastic container instances to ALB. For CLB instances, you can directly add elastic container instances to the default server group.

  4. Configure listeners

    A listener is a device that checks client requests from clients and forwards healthy client requests to backend servers. You must configure listeners for your SLB instance. A listener includes a protocol, ports, and scheduling algorithms.

In the following section, CLB is used as an example to describe how to add elastic container instances to an SLB instance. You can follow the same procedure to add elastic container instances to an ALB instance. For more information about how to add elastic container instances to an ALB instance, see Quick start.

Preparations

  1. Create multiple elastic container instances.

    In this example, two elastic container instances that run on the NGINX web server 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.

    slb1
  2. Create a CLB instance.

    Create a CLB instance that allows access from the Internet. For more information, see Create a CLB instance.

    slb2

Procedure

If you add elastic container instances as backend servers to a CLB instance and configure listeners, the CLB instance can forward requests from clients to the elastic container instances.

Note

If an elastic container instance is in a final state such as the Succeeded or Failed state, you cannot add the instance as a backend server to a CLB instance.

After you bind elastic network interfaces (ENIs) to your elastic container instances, you can call a CLB API operation to add the ENIs to your CLB instance. You can also call a CLB API operation to configure listeners. Perform the following steps:

  1. Call the DescribeContainerGroups operation that is provided by Elastic Container Instance to query the information about the elastic container instance.

    Obtain the following information about the elastic container instance from the response parameters:

    • The ID of the ENI instance. The EniInstanceId parameter indicates the ID of the ENI instance.

    • The internal IP address of the elastic container instance. The IntranetIp parameter indicates the internal IP address of the elastic container instance.

  2. Call the AddBackendServers operation to add a backend server.

    The following table describes the main request parameters. For more information, see AddBackendServers.

    Parameter

    Type

    Example

    Description

    LoadBalancerId

    String

    lb-2ze7o5h52g02kkzz******

    The ID of the CLB instance.

    BackendServers

    String

    [{ "ServerId": "eni-6wejdtelaz2bv526****", "Weight": "100", "Type": "eni", "ServerIp": "172.16.12.**", "Port":"80","Description":"test" },{ "ServerId": "eni-6wejdtelaz2bv321****", "Weight": "100", "Type": "eni", "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 ENI instance that is bound to the elastic container instance.

    • Weight: The weight of the backend server. Valid values: 0 to 100. Default value: 100. If the value is set to 0, no requests are forwarded to the backend server.

    • Description: The description of the backend server. The description must be 1 to 80 characters in length.

    • Type: The type of the backend server. Set this parameter to eni.

    • ServerIp: The IP address of the backend server. Enter the internal IP address of the elastic container instance.

  3. Call the following operations to create listeners:

    • CreateLoadBalancerTCPListener: creates a TCP listener.

    • CreateLoadBalancerUDPListener: creates a UDP listener.

    • CreateLoadBalancerHTTPListener: creates an HTTP listener.

    • CreateLoadBalancerHTTPSListener: creates an HTTPS listener.

    In this example, a TCP listener is created. The following table describes the main request parameters that are used to create the TCP listener. For more information, see CreateLoadBalancerTCPListener.

    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 this value to -1. A value of -1 specifies that the bandwidth is unlimited.

    • 1 to 5120: For a pay-by-bandwidth Internet-facing CLB instance, you can specify the maximum bandwidth for each listener. The sum of the maximum bandwidth values of all listeners cannot exceed the maximum bandwidth of the CLB instance. Unit: Mbit/s.

    BackendServers

    Integer

    80

    The backend port that is used by the CLB instance.

    Valid values: 1 to 65535.

    LoadBalancerId

    String

    lb-2ze7o5h52g02kkzz******

    The ID of the CLB instance.

    ListenerPort

    Integer

    80

    The frontend port that is used by the CLB instance.

    Valid values: 1 to 65535.

  4. Call the StartLoadBalancerListener operation to enable the listener.

Verify that the elastic container instances are added to the CLB instance

  1. Run the following command multiple times to send requests to the public IP address of the CLB instance:

    curl 39.106.**.** 80
  2. View the logs of the elastic container instances. The logs show that the CLB instance forwards the requests to different elastic container instances.