Add or remove a target
Send a load balancer's traffic to an instance or an IP address, or stop sending it there.
A target is one of your instances (server) or an IP address (ip). Every target serves every
service of the load balancer, except on application, where a target serves its target group.
Replace i-0123456789abcdef with your instance's id.
Prerequisites
- Permission for
lb:AddTargetto add a target,lb:RemoveTargetto remove one. They are separate, so someone can be allowed to take a broken backend out without being allowed to add new ones. Withoutlb:AddTargetthe Targets tab says "Adding a target needs lb:AddTarget." in place of the button; withoutlb:RemoveTargetthe rows have no remove control. - In the console, also
lb:DescribeLoadBalancerson the load balancer (without it its page answers 404), andec2:DescribeInstancesto pick an instance from the list. - An instance in the load balancer's region. What else it needs depends on the type:
| Type | An instance target | An IP target |
|---|---|---|
lb11, lb21, lb31 |
reached at its public address, or with usePrivateIp at its VPC address (the load balancer must have been created with vpcId) |
any IPv4 address the load balancer can reach |
application |
needs a public IPv4 (in an organization whose load balancers run on its own hosts: reached at its site address instead) | a public address that is not the platform's own |
dedicated, public |
needs a public IPv4 | a public address that is not the platform's own |
dedicated, private |
must be in the load balancer's VPC and have an address there | inside the VPC's range |
On application the target joins a target group (targetGroup, default default). The other
types refuse any group but default. The console's Add target form has no private-address
option: add a usePrivateIp target with the CLI, API or Terraform.
Add a target
- Open Load balancers, open the load balancer, then the Targets tab.
- Choose Add target.
- For Target type, choose Instance or IP address.
- For Instance, pick the instance, or for IP address, enter the address. Instances the
load balancer cannot use are greyed with the reason: terminated or being terminated, in
another region, already a target (not on
application, where one instance may serve several target groups), or without a public address (applicationonly). - On
application, (optional) for Target group, enter a group; empty meansdefault. - Choose Add.
dcloud lb targets add lb-id --type server --instance-id i-0123456789abcdef \
--use-private-ip--use-private-ip only on lb11–lb31 created in a VPC. An address: --type ip --ip 192.0.2.10.
POST /lb/api/load-balancers/lb-id/targets
{ "type": "ip", "ip": "192.0.2.10" }resource "dcloud_lb_target" "web" {
load_balancer_id = dcloud_lb.web.id
type = "server"
instance_id = "i-0123456789abcdef"
}The new target is in the Targets tab. On application and dedicated the fleet picks it up
within seconds; its status is unknown on application until the fleet has checked it. On
lb11–lb31 it is registered at the provider in the background and its status is healthy.
When adding is refused
400instanceId is required for server targets,400ip is required for ip targets.400when the instance is in another region than the load balancer.400usePrivateIp needs a load balancer in a VPC: create it with vpcId, or target the public addressonlb11–lb31; onapplication,usePrivateIpis always refused with400. Ondedicatedit is ignored: the scheme decides which address is used.400onapplicationand publicdedicatedfor an instance without a public IPv4 or an address that is not public; on privatededicatedfor an instance or address outside the VPC.400over 25 targets (application,dedicated) or 10 target groups (application), and for a target group on another type.409for a load balancer another service owns.
Remove a target
- On the Targets tab, on the target's row, choose the remove control (Remove target).
- Choose Delete.
dcloud lb targets remove lb-id target-idDELETE /lb/api/load-balancers/lb-id/targets/target-idRemove the dcloud_lb_target resource and apply.
The answer is 200 with the target's id, also for a target id that does not exist. The
instance keeps running. 409 for a load balancer another service owns.