Health checks
A health check is a small test the load balancer runs against each target on a schedule. A target that fails enough checks in a row is taken out of service, so users don’t reach a broken VM. When it passes again, it is put back automatically. You don’t have to remove or re-add anything yourself.
When to use each type of check
There is no HTTPS check. For a VM that serves only TLS on its port, use Port is open. UDP targets aren’t health-checked: the portal shows “UDP health checks are not available.”
An HTTP response check on a path your app doesn’t serve (for example a 404 on /) fails on every target. With no healthy target, all traffic stops. Test the path first.
How it works
- Every interval (default 10 seconds), the load balancer checks each target on its backend port and waits up to the timeout (default 3 seconds) for an answer.
- After unhealthy threshold failed checks in a row, the target is taken out of service. A failure is a refused connection, no answer within the timeout, or, for an HTTP check, a status other than
200. - Checks keep running against the removed target. After healthy threshold passed checks in a row (default
1), it gets traffic again. - If no target is healthy, traffic stops until at least one passes again.
Defaults and timing
These are the API defaults when you leave a field out. The portal’s check starts as Port is open with “Every 10s · 3s timeout · unhealthy after 3 fails · healthy after 1 pass”.
Before you begin
- The backend port open in each VM’s firewall group. Checks use the same port as traffic. See Create firewall rules.
- For an HTTP check, a health path on every target, such as
/healthz, that returns HTTP200without a login. Return200only when the app can really serve requests.
Test the path from your computer before you rely on it:
The first line of the answer should be HTTP/1.1 200 OK. Any other status, including a redirect such as 301, counts as a failure.
Set a health check in the portal
Find Health check
On the Create Load Balancer page, under Routing, find Health check: “Unhealthy targets stop receiving traffic until they recover.” The toggle is on.
Choose the type
Keep Port is open (“Passes when each target’s backend port accepts a connection.”), or choose HTTP response and enter a path such as /healthz (“Passes on 200 from each target’s backend port.”).
Edit the timing (optional)
Click Edit timing to see every field:
The expanded form also shows Hostname (optional) and Accepted HTTP responses. For an HTTP check these are hostname (the Host header the check sends) and expected_statuses (default [200]) in the API. The form’s Health check port (optional) isn’t available yet: the current gateway refuses a separate check port, so checks use the traffic port.
To change the check later, open the load balancer, click Settings, then Edit next to Health check, and Save.
To turn checks off, switch the toggle off: “Off. Traffic goes to every target, whether it responds or not.” Do this only if you check your VMs some other way.
Set a health check with the API
The health check belongs to a target group, so each group can have its own. Send it in health_check when you create the load balancer, or change it with PUT and the whole specification.
"health_check": null turns checks off for that group.
This target group checks /healthz over HTTP every 10 seconds and leaves unhealthy_threshold out, so it is 1:
For a Network load balancer, use {"protocol": "TCP"}, which takes the defaults. See Create a load balancer for the full request.
Verify
- Stop the app on one VM, or make its health path return
503. - Wait for the removal time from the table above: about 30 seconds for a TCP check with the defaults, about 10 seconds for an HTTP check.
- Send requests to the load balancer’s address. They should all reach the other VMs.
- Start the app again. About 10 seconds later, that VM gets traffic again.
