Get started with an application load balancer
Put an application load balancer in front of an instance that serves HTTP, reach it at its own name, and delete it again.
This tutorial uses the application type, because it answers at a name of its own as soon as it
is active, with no DNS record of yours. Replace web-lb with the name you want and de1 with your
region.
Prerequisites
- An instance in the same region with a public IPv4 address, serving HTTP on port 80. An application load balancer reaches an instance over its public address. (In an organization whose load balancers run on its own hosts, it reaches the instance at its site address instead, and no public address is needed.)
- Permission for
lb:CreateLoadBalancer,lb:AddService,lb:AddTarget,lb:DescribeLoadBalancersand, for the clean-up,lb:DeleteLoadBalancer. - In the console,
lb:DescribeLoadBalancersto open Load balancers (without it the page says you do not have permission to view load balancers), andec2:DescribeInstancesto pick the instance from a list. - Room in the
lb.load-balancersquota of the region.
Step 1: Create the load balancer
Important
You pay for an application load balancer from the hour it is active until you delete it, at most €4.99 a month.
- Open Load balancers, then choose Create load balancer.
- For Name, enter web-lb.
- For Region, choose your region.
- For Type, choose the
applicationentry. - Choose Create.
The load balancer appears in the list with the status provisioning, and turns active once the
fleet carries it.
dcloud lb load-balancers create --name web-lb --type application --region-id de1POST /lb/api/load-balancers
{ "name": "web-lb", "type": "application", "regionId": "de1" }The answer is 201 with the new load balancer, its status provisioning and its id.
Step 2: Add an HTTP service
The service listens on port 80 and forwards to port 80 on the target.
- Open the load balancer, then the Services tab.
- Choose Add service.
- Keep Protocol on HTTP, Source port on 80 and Destination port on 80.
- Choose Add.
dcloud lb services add lb-id --protocol http --source-port 80 --destination-port 80POST /lb/api/load-balancers/lb-id/services
{ "protocol": "http", "sourcePort": 80, "destinationPort": 80 }Step 3: Add your instance as a target
- Open the Targets tab, then choose Add target.
- Keep Target type on Instance, and for Instance, pick your instance.
- Choose Add.
The target shows the status unknown until the fleet has checked it, then healthy.
dcloud lb targets add lb-id --type server --instance-id i-0123456789abcdefPOST /lb/api/load-balancers/lb-id/targets
{ "type": "server", "instanceId": "i-0123456789abcdef" }Step 4: Send a request
On the Overview tab, under Names, copy the platform name, then request it:
curl -i http://web-lb-1a2b3c4d.lb.apps.example.com/The answer comes from your instance. If the health check (a GET / on port 80) has taken the target
out of rotation, the load balancer answers 503 instead. With the CLI, the name is the hostname field of
dcloud lb load-balancers get lb-id.
Clean up
Deleting the load balancer removes its services and targets; the instance keeps running.
- Open the load balancer, then the Danger zone tab.
- Choose Delete load balancer.
- Type the load balancer's name, then choose Delete load balancer.
dcloud lb load-balancers delete lb-idDELETE /lb/api/load-balancers/lb-id