Attach VMs
A target is a VM and a port that a load balancer sends traffic to. Attaching a VM means adding it as a target; there is no separate “attach” button. You pick VMs when you create the load balancer, and you can add or remove them later. The load balancer health-checks each target and sends traffic only to the healthy ones.
When to use each kind of target
resource_id is the VM’s ID: the id that GET /compute/cloud-vms returns for the VM. Check a location’s capabilities with GET /networking/load-balancers/regions.
How it works
- You choose the targets and the backend port. In the portal, every forwarding rule sends traffic to all the VMs you pick, on the rule’s backend port. In the API, each target has its own
port. - Before anything is reserved, IBEE checks that the location can reach every target. If it can’t reach one, the request is refused with
422target_not_usable, and nothing is reserved. - The load balancer attaches the targets. In the API,
conditions.backend_readybecomestrue; in the portal, the status leaves “Connecting to your targets”. - The load balancer health-checks each target on its backend port. Targets that pass get traffic, chosen by the algorithm.
Before you begin
- Running VMs in the same location as the load balancer, with the same app listening on the same port on every VM. See Create a VM.
- A public IP address on each VM, unless the location supports private targets. The
public_ipfield ofGET /compute/cloud-vms, and the VM’s page in the portal, show it. - The app port open in each VM’s firewall group. The load balancer connects to that port for traffic and for health checks, so a rule that allows only your own IP address isn’t enough. See Create firewall rules. Also check the firewall inside the VM (
ufw,firewalldor Windows Firewall). - A little patience with new VMs. A new VM reports
runningabout 20 seconds before its SSH or web server answers. Wait before you test traffic through the load balancer.
Add VMs when you create the load balancer
Check each VM answers
From your computer, connect to the app port on each VM’s public address:
Each should answer. If a request times out, open the port in the VM’s firewall group first.
Open the create form
Under Network & Security, click Load Balancer, then Create Load Balancer. Choose the Location where your VMs run.
Set the backend port
Under Forwarding rules, set the Backend protocol and Port to the port your app listens on, for example HTTP 8080.
Add or remove VMs later
In the portal: open the load balancer, click Settings, then Edit next to Targets. Add or remove VMs and click Save. The Overview tab shows the number of targets.
With the API: read the load balancer, change the targets list in its specification, and send the whole specification back with PUT and the version you read. The list you send replaces the current one, so include every VM you want to keep.
The call answers 202 with an update operation. A stale version answers 409 version_conflict. The token needs load-balancer.write. See Change a load balancer.
Targets of a load balancer made by a Kubernetes cluster (managed_by ccm) can’t be changed here. Change the Service in your cluster instead.
Before you delete a VM that is a target, remove it from the load balancer first, in the portal or with a PUT.
Verify
-
Open the load balancer. The Overview tab shows Targets with the number of VMs and their names.
-
Make each VM identify itself, for example with a
/whoamipage that returns the VM’s hostname. -
Send several requests to the load balancer’s address and count the answers:
Every healthy VM should appear. See Algorithms for how the requests are spread.
