Create a load balancer
Create a load balancer of one of the five types in a region, public or, for the network and dedicated types, attached to a VPC.
A new load balancer has no services and no targets: it carries traffic once you add both. Replace web-lb with your name and de1 with the region of the instances it will serve; a load balancer reaches targets of its own region only.
Important
The type, algorithm, region, VPC and, for dedicated, the scheme are fixed at creation. You pay
for the load balancer per hour from when it exists (lb11–lb31) or is active
(application, dedicated) until you delete it.
Prerequisites
- Permission for
lb:CreateLoadBalancer. - Room in the
lb.load-balancersquota of the region. - Any tag keys your organization requires.
- For a private
dedicatedload balancer, a VPC in the region that already has an instance or a database in it. - To attach a web ACL at creation (
application, CLI, API or Terraform), alsolb:SetWebAcl, andwaf:GetWebAclon the ACL. - In the console, also
lb:DescribeLoadBalancersto open Load balancers; without it the page says you do not have permission to view load balancers. For a privatededicatedload balancer, alsoec2:DescribeVpcs, which fills the VPC list. Withoutlb:CreateLoadBalancer, Create load balancer stays off and the page says "Creating a load balancer needs lb:CreateLoadBalancer. Ask an administrator."
Create it
- Open Load balancers, then choose Create load balancer.
- For Name, enter web-lb.
- For Region, choose the region.
- For Type, choose the type. The form starts on
lb11. - For a
dedicatedload balancer, for Reachable from, choose Public: its own IPv4 and IPv6 or Private: addresses in a VPC only. For private, choose the VPC. - For Algorithm, keep Round robin or choose Least connections.
- (Optional) Under Tags, add tags.
- Choose Create.
The load balancer appears in the list as provisioning. The console cannot attach an lb11,
lb21 or lb31 to a VPC; use the CLI, API or Terraform for that.
dcloud lb load-balancers create --name web-lb --type lb11 --region-id de1 \
--algorithm least_connectionsA private dedicated load balancer:
dcloud lb load-balancers create --name internal-lb --type dedicated --scheme private \
--vpc-id vpc-id --region-id de1POST /lb/api/load-balancers
{ "name": "web-lb", "type": "lb11", "algorithm": "round_robin", "regionId": "de1" }The answer is 201 with the load balancer, its status provisioning. Its addresses are filled
in once it is placed; read it with GET /lb/api/load-balancers/{id}.
resource "dcloud_lb" "web" {
name = "web-lb"
type = "lb11"
algorithm = "round_robin"
region_id = "de1"
}Changing name, type, algorithm, region_id, scheme or vpc_id replaces the load
balancer.
Options by type
| Field | lb11, lb21, lb31 |
application |
dedicated |
|---|---|---|---|
vpcId |
optional: join the VPC's network | refused (400) | required with scheme: "private", refused with public |
scheme |
refused (400) | refused (400) | public (default) or private |
webAclId |
refused (400) | optional | refused (400) |
algorithm |
round_robin (default) or least_connections |
same | same |
Result
The status goes from provisioning to active once the load balancer has its addresses (or, on
the fleet, is placed). An application or dedicated load balancer also gets a name,
hostname. If creation fails, the status is error and the reason is shown on its page as
Provisioning failed.
When it is refused
400scheme is for type "dedicated" only.400A private load balancer lives in a VPC: give vpcId.400forvpcIdon anapplicationload balancer, or on a publicdedicatedone.404Region not found,404VPC not found;400when the VPC is in another region.409when the region's load balancer quota is used up; the message starts withQuota exceeded:.409for a privatededicatedload balancer whose VPC has no network yet, or whose VPC already holds 5 load balancer address pairs.409with the codeprovider_unsupportedfor any type butapplicationin an organization whose load balancers run on its own hosts.- For
webAclId:400on any type butapplication,404for an ACL that is not your organization's,403withoutwaf:GetWebAclon it.