Updated on 2023-12-18 GMT+08:00

Creating a Load Balancer

Scenarios

Assume that you have created a VPC and several ECSs on the cloud platform. To ensure high performance and availability of ECSs, a load balancer is required to distribute requests to different backend ECSs.

This section describes how to invoke the API to create a load balancer.

The validity period of a token obtained from IAM is 24 hours. If you want to use a token for authentication, cache it to avoid frequently calling the IAM API.

Involved APIs

If you use a token for authentication, you must obtain the token and add X-Auth-Token to the request header of the ELB API when making an API call.

  • IAM API used to obtain the token
  • ELB API used to create a load balancer

Procedure

  1. Obtain the token by referring to Authentication.
  2. Send POST https://ELB endpoint/v2.0/lbaas/loadbalancers.
  3. Add X-Auth-Token to the request header.
  4. Specify the following parameters in the request body:
    {
        "loadbalancer": {
            "name": "loadbalancer1", //Load balancer name
            "description": "simple lb", //Load balancer description
            "vip_subnet_id": "58077bdb-d470-424b-8c45-2e3c65060a5b", //ID of the IPv4 subnet where the load balancer works
            "vip_address": "10.0.0.4" //IP address of the load balancer
        }
    }

    If the request is successful, the response body is returned.

    If the request fails, an error code and error information are returned. For details, see Status Codes.