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

Creating a Load Balancer

Assume that you have created a Virtual Private Cloud (VPC) and several Elastic Cloud Servers (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.

API Format

Method

URI

Description

POST

/v2.0/lbaas/loadbalancers

Creates a load balancer.

Procedure

  1. Set the request header.

    Set the header in Postman and place the obtained token in the header.

    Figure 1 Request header

    The value of the token can be transferred through an environment variable or directly entered.

  2. Under Body, set the request body.

    Figure 2 Request body

    You can refer to Sample Code to set the request body, or add other required fields by referring to the Elastic Load Balance API Reference.

  3. Enter the URL.

    The request URL consists of the following parts:

    Endpoint

    URI

    https://

    elb

    .cn-north-1

    .myhuaweicloud.com

    /v2.0/lbaas/loadbalancers

    -

    Service name

    Region

    Endpoint

    URI

  4. Send the request. Set the POST request method and click Send to wait for response from the server.

    {
        "loadbalancer": {
            "description": "simple lb",
            "admin_state_up": true,
            "tenant_id": "0d0bf0e8fb564cc9abbe526dbdca9248",
            "provisioning_status": "ACTIVE",
            "vip_subnet_id": "8d944cda-1f29-4035-9681-ad8c5117fbc5",
            "listeners": [],
            "vip_address": "192.168.0.144",
            "vip_port_id": "b06bdc8f-cc00-41b4-8aba-280a333342ee",
            "provider": "vlb",
            "pools": [],
            "id": "bb2f1569-4c03-4e48-8e02-a2d831c0db56",
            "operating_status": "ONLINE",
            "name": "loadbalancer4guide"
        }
    }

    If the request is correct, information about the newly created load balancer is displayed. After logging in to the web console, you can see a load balancer named loadbalancer4guide.

Sample Code

Request body in 2

{ 
    "loadbalancer": { 
        "name": "loadbalancer1", 
        "description": "simple lb", 
        "vip_subnet_id": "58077bdb-d470-424b-8c45-2e3c65060a5b", 
        "admin_state_up": true 
    } 
} 

The value of vip_subnet_id is the ID of the subnet where the create load balancer works.