Help Center/ Elastic Load Balance/ API Reference/ Examples/ Creating a Public Network (Shared) Load Balancer
Updated on 2024-07-27 GMT+08:00

Creating a Public Network (Shared) Load Balancer

Scenarios

Call APIs to create a load balancer and bind a new EIP to it.

Prerequisites

You have created a VPC and a subnet.

Procedure

Bind an EIP to the port that has been bound to the private IP address of the load balancer. For details about the parameters, see Table 1.

Table 1 Request parameters

Parameter

Mandatory

Type

Description

publicip

Yes

Object

Specifies the EIP. For details, see Table 2.

bandwidth

Yes

Object

Specifies the bandwidth. For details, see Table 3.

enterprise_project_id

No

String

  • Specifies the enterprise project ID. The value is 0 or a UUID that can contain a maximum of 36 characters, including hyphens (-).
  • When assigning an EIP, you need to bind an enterprise project ID to the EIP.
  • If this parameter is not specified, the default value is 0.
NOTE:

For more information about enterprise projects and how to obtain enterprise project IDs, see Enterprise Management User Guide.

Table 2 publicip parameter description

Parameter

Mandatory

Type

Description

type

Yes

String

  • Specifies the EIP type.
  • The value can be 5_telcom, 5_union, 5_bgp, or 5_sbgp.
    • CN South-Guangzhou: 5_bgp and 5_sbgp
    • CN East-Shanghai2: 5_bgp and 5_sbgp
    • CN North-Beijing1: 5_bgp and 5_sbgp
    • CN-Hong Kong: 5_bgp
    • CN Southwest-Guiyang1: 5_bgp and 5_sbgp
    • CN North-Beijing4: 5_bgp and 5_sbgp
  • Note:
    • The configured value must be supported by the system.
    • publicip_id is an IPv4 port. If publicip_type is not specified, the default value is 5_bgp.

ip_version

No

Integer

  • Specifies the EIP version.
  • The value can be 4 and 6. 4 indicates an IPv4 address, and 6 indicates an IPv6 address.
  • Note:
    • The configured value must be supported by the system.
    • If this parameter is left blank or is an empty string, an IPv4 address is assigned by default.

ip_address

No

String

  • Specifies the EIP to be assigned. The system automatically assigns an EIP if you do not specify it.
  • The value must be a valid IPv4 address in the available IP address range.
Table 3 bandwidth parameter description

Parameter

Mandatory

Type

Description

name

No

String

  • Specifies the bandwidth name.
  • The value can contain 1 to 64 characters that can contain letters, digits, underscores (_), hyphens (-), and periods (.).
  • This parameter is mandatory when share_type is set to PER. This parameter will be ignored when share_type is set to WHOLE with an ID specified.

size

No

Integer

  • Specifies the bandwidth (Mbit/s).
  • The value ranges from 1 to 300 by default (The specific range may vary depending on the configuration in each region. You can see the bandwidth range of each region on the management console.)
  • This parameter is mandatory when share_type is set to PER. This parameter will be ignored when share_type is set to WHOLE with an ID specified.
  • The minimum unit for bandwidth adjustment varies depending on the bandwidth range. The details are as follows:
    • The minimum increment is 1 Mbit/s if the allowed bandwidth ranges from 0 to 300 Mbit/s.
    • The minimum increment is 50 Mbit/s if the allowed bandwidth ranges from 301 Mbit/s to 1000 Mbit/s.
    • The minimum increment is 500 Mbit/s if the allowed bandwidth is greater than 1,000 Mbit/s.

id

No

String

  • Specifies the bandwidth ID. You can specify an existing shared bandwidth when assigning an EIP.
  • The value can be the ID of the shared bandwidth whose type is set to WHOLE.

share_type

Yes

String

  • Specifies the bandwidth type.
  • The value can be one of the following:
    • PER: indicates dedicated bandwidth.
    • WHOLE: indicated shared bandwidth.

charge_mode

No

String

  • The default value is traffic. Currently, only billing by traffic is supported.
  • Step 1: Apply for an EIP.
    POST https://{VPCEndpoint}/v1/8b7e35ad379141fc9df3e178bd64f55c/publicips
    
    {
        "publicip": {
            "type": "5_bgp",
            "ip_version": 4
        },
        "bandwidth": {
            "name": "bandwidth123",
            "size": 10,
            "share_type": "PER"
        }
    }
  • Example response
    {
        "publicip": {
            "id": "f588ccfa-8750-4d7c-bf5d-2ede24414706",
            "status": "PENDING_CREATE",
            "type": "5_bgp",
            "public_ip_address": "139.9.204.183",
            "tenant_id": "8b7e35ad379141fc9df3e178bd64f55c",
            "ip_version": 4,
            "create_time": "2019-06-29 06:45:32",
            "bandwidth_size": 1
            
        }
    }
  • Step 2: Bind the EIP. (The value of public_id is the same as that in the ▪ Example response, and the value of port_id is the same as that of vip_port_id in Example response 1.)
    PUT /v1/8b7e35ad379141fc9df3e178bd64f55c/publicips/f588ccfa-8750-4d7c-bf5d-2ede24414706
    
    {
        "publicip": {
            "port_id": "a7ecbdb5-5a63-41dd-a830-e16c0a7e04a7"
        }
    }
  • Example response
    {
      "publicip": {
        "id": "f588ccfa-8750-4d7c-bf5d-2ede24414706",
        "status": "ACTIVE",
        "type": "5_bgp",
        "port_id": "a7ecbdb5-5a63-41dd-a830-e16c0a7e04a7",
        "public_ip_address": "139.9.204.183",
        "private_ip_address": "192.168.1.131",
        "tenant_id": "8b7e35ad379141fc9df3e178bd64f55c",
        "create_time": "2019-06-29 07:33:18",
        "bandwidth_size": 1,
        "ip_version": 4
      }
    }
  • After the preceding steps are complete, the load balancer has the capability of accessing the public network. You can access the load balancer using 139.9.204.183, the value of parameter public_ip_address.