Attach VMs
A backend is an address and port that a load balancer sends traffic to. Attaching a VM to a load balancer means adding the VM’s address as a backend; there is no separate “attach” button. You list each VM’s address in the load balancer’s backends, and the load balancer starts health-checking and sending traffic to it.
When to use each backend type
The load balancer isn’t inside any of your VPCs, so it can’t reach a VM’s VPC private address (for example 10.144.0.5). A VM in a Private only VPC, or one that reaches the internet only through a Managed NAT Gateway (shared outbound address), needs its own public address before it can be a backend: attach a Reserved IP to it.
How it works
- You add one backend per VM: its public IPv4 address and the port your app listens on.
- The load balancer sends a health check to each VM on that port.
- VMs that pass get traffic, in proportion to their Weight.
- Your app on each VM sees the connections coming from the load balancer, not from the visitor.
Before you begin
- Two or more running VMs with the same app, listening on the same port on every VM. See Create a VM.
- Each VM’s public IPv4 address, shown in the IP Address column of the VM list and on the VM’s detail page.
- The app port open in each VM’s firewall group. The default firewall group accepts TCP
80,443and8000–8080from anywhere. For any other port, add an accept rule. See Create firewall rules. Also check the firewall inside the VM (ufw,firewalldor Windows Firewall). - A health endpoint on each VM, such as
/healthreturning HTTP200. See Health checks.
Add VMs when you create the load balancer
Collect the addresses
In the sidebar, under Infrastructure, click Cloud VMs (or GPU VMs). Note each VM’s public IPv4 address from the IP Address column.
Check each VM answers
From your computer, request the health endpoint on each VM:
Each should return HTTP/1.1 200 OK. 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. Set the name, layer and protocol.
Add or remove a VM later
The portal can’t edit a load balancer’s backends. Use the API’s PATCH, which keeps the load balancer’s hostname. The backends list you send replaces the current list, so include every VM you want to keep.
This request adds a third VM to an L7 load balancer:
To remove a VM, send the list without it. For an L4 load balancer, use /networking/load-balancers/l4/LB-ID. The token needs load-balancer.write.
Without the API, create a new load balancer with the new list, point your DNS record at its new Host, and then delete the old one.
Before you delete or rebuild a VM that is a backend, remove it from the list (or let its health check fail). A deleted VM’s address can later be given to someone else’s server, and the load balancer would keep sending traffic to it. Keep VM addresses stable with Reserved IPs.
Verify
-
Open the load balancer’s detail page. Backends lists every VM with its Port, Weight and Backend TLS setting.
-
Make each VM identify itself, for example with a
/whoamipage that returns the VM’s hostname. -
Send several requests to the load balancer and count the answers:
With equal weights and round robin, each VM answers about the same number of times.
Maintenance without downtime
You don’t need to remove a VM for a short restart. Its health check fails, and with the default settings it stops getting traffic after about 30 seconds. It gets traffic again about 20 seconds after it recovers. To avoid errors during those 30 seconds, take it out first with a PATCH that leaves it out of the list, restart it, then add it back.
