Help Center> Elastic Load Balance> API Reference> Examples> Creating a Shared Load Balancer

Creating a Shared Load Balancer

Scenarios

Call APIs to create a shared load balancer as a user who has enabled the enterprise project function.

Prerequisites

  • You have created a VPC and a subnet.
  • 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 a call. Obtain the token by following instructions in Authentication.

    The token obtained from IAM is valid for only 24 hours. If you want to use a token for authentication, you can cache it to avoid frequent calling.

Procedure

  1. Query the subnet you have created.
    1. Send GET https://{vpc_endpoint}/v1/{project_id}/subnets. project_id indicates the project ID.
    2. Add X-Auth-Token to the request header.
    3. Check the response.
      • The request is successful if the following response is displayed:
        {
            "subnets": [
                {
                     "id": "00ab3183-0b8f-4618-abf2-c70bc33a1876", // Subnet ID
                     "name": "subnet-ipv6-test", // Subnet name
                    "description": "",
                    "cidr": "192.168.0.0/24", //IPv4 address range
                    "dnsList": [
                        "100.125.4.6"
                    ],
                    "status": "ACTIVE",
                     "vpc_id": "19624562-5e03-4b5a-ad28-de537dfb27d2", // VPC ID
                    "ipv6_enable": true,
                    "gateway_ip_v6": "2001:db8:a583:1e9::1",
                    "cidr_v6": "2001:db8:a583:1e9::/64",
                    "gateway_ip": "192.168.0.1",
                    "dhcp_enable": true,
                    "primary_dns": "100.125.4.6",
                    "availability_zone": "br-iaas-odin1a", // AZ
                     "neutron_network_id": "00ab3183-0b8f-4618-abf2-c70bc33a1876", // Network ID
                    "neutron_subnet_id": "db2e598a-812e-4321-a6be-80fe63ee9306", // IPv4 subnet ID
                    "neutron_subnet_id_v6": "2f11a7fe-dfc4-4c8c-a4b2-a7009f7b056c",
                    "extra_dhcp_opts": []
                }
        	]
        }
      • If the request is abnormal, rectify the fault by referring to HTTP Status Codes of Shared Load Balancers.
  2. Create a load balancer.
    1. Send POST https://{elb_endpoint}/v2/{project_id}/elb/loadbalancers. project_id indicates the project ID.
    2. Add X-Auth-Token to the request header.
    3. Ensure that the following parameters are passed in the request body:
      {     
          "loadbalancer": {
              "name": "loadbalancer1", // Load balancer name
              "vip_subnet_id": "db2e598a-812e-4321-a6be-80fe63ee9306" // IPv4 subnet ID returned in the step for querying subnet information
          }
      }
    4. Check the response.
      • The request is successful if the following response is displayed:
        {
            "loadbalancer": {
                "tenant_id": "060576782980d5762f9ec014dd2f1148", // Tenant ID
                "listeners": [],
                "provisioning_status": "ACTIVE",
                "description": "",
                "pools": [],
                "created_at": "2020-10-26T13:41:23",
                "vip_subnet_id": "db2e598a-812e-4321-a6be-80fe63ee9306", // IPv4 subnet ID
                "tags": [],
                "enterprise_project_id": "0",
                "vip_address": "192.168.0.90",
                "updated_at": "2020-10-26T13:41:25",
                "provider": "vlb",
                "operating_status": "ONLINE",
                 "project_id": "060576782980d5762f9ec014dd2f1148", // Project ID, same as the tenant ID
                "admin_state_up": true,
                "name": "loadbalancer1",
                "id": "cdae731a-9d9d-4275-9412-b08a847f3a4c", // Load balancer ID
                "vip_port_id": "365f011b-fa93-45d6-bfc0-2b8b83880a8b" // ID of the port bound to the private IP address of the load balancer
            }
        }
      • If the request is abnormal, rectify the fault by referring to HTTP Status Codes of Shared Load Balancers.
  3. Assign an EIP or bind an existing EIP to the load balancer if you want it to receive requests over the Internet.
    • To assign an EIP, go to 4.
    • To bind an existing EIP, go to 5.
  4. Assign an EIP.
    1. Send POST https://{vpc_endpoint}/v1/{project_id}/publicips. project_id indicates the project ID.
    2. Add X-Auth-Token to the request header.
    3. Ensure that the following parameters are passed in the request body:
      {
          "publicip": {
              "type": "5_bgp", // EIP type
               "ip_version": 4 // IP address version
          },
          "bandwidth": {
              "name": "bandwidth123", // Bandwidth name
              "size": 10, // Bandwidth size
              "share_type": "PER" //Bandwidth type. PER indicates dedicated bandwidth, and WHOLE indicates shared bandwidth.
          }
      }
    4. Check the response:
      {
          "publicip": {
              "id": "f588ccfa-8750-4d7c-bf5d-2ede24414706", // EIP ID, required in the next step
              "status": "PENDING_CREATE",
              "type": "5_bgp",
              "public_ip_address": "139.9.204.183",
              "tenant_id": "060576782980d5762f9ec014dd2f1148",
              "ip_version": 4,
              "create_time": "2019-06-29 06:45:32",
              "bandwidth_size": 1,
              "enterprise_project_id":"0"
          }
      }
  5. Bind an existing EIP.
    1. Send POST https://{vpc_endpoint}/v1/{project_id}/elb/publicips/{public_id}. project_id indicates the project ID, and public_id indicates the public IP address ID returned in the step for assigning an EIP.
    2. Add X-Auth-Token to the request header.
    3. Ensure that the following parameters are passed in the request body:
      {
          "publicip": {
              "port_id": "365f011b-fa93-45d6-bfc0-2b8b83880a8b" // Value of vip_port_id returned in the step for creating a load balancer
          }
      }
    4. Check the response.
      {
        "publicip": {
          "id": "f588ccfa-8750-4d7c-bf5d-2ede24414706",
          "status": "ACTIVE",
          "type": "5_bgp",
          "port_id": "365f011b-fa93-45d6-bfc0-2b8b83880a8b",
          "public_ip_address": "139.9.204.183",
          "private_ip_address": "192.168.1.131",
          "tenant_id": "060576782980d5762f9ec014dd2f1148",
          "create_time": "2019-06-29 07:33:18",
          "bandwidth_size": 1,
          "ip_version": 4
        }
      }
  6. Access the load balancer using 139.9.204.183, the value of parameter public_ip_address.