Skip to navigation

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

Check in the portalAPI protocolWhat passesUse it when
Port is open (default)TCPThe target’s backend port accepts a connectionAny app, including databases, SSH and TLS passthrough. It works without a health endpoint.
HTTP responseHTTPThe target answers an HTTP request for the path with status 200Your app serves HTTP and has a health path, such as /healthz, that returns 200 without a login

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

  1. 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.
  2. 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.
  3. Checks keep running against the removed target. After healthy threshold passed checks in a row (default 1), it gets traffic again.
  4. If no target is healthy, traffic stops until at least one passes again.

Defaults and timing

SettingPort is open (TCP)HTTP response (HTTP)
Interval10 seconds10 seconds
Timeout3 seconds3 seconds
Unhealthy threshold31, the only value supported for HTTP checks today
Healthy threshold11
A target stops answering → it is taken outAbout 30 seconds (3 failed checks, 10 seconds apart)About 10 seconds (1 failed check)
A target recovers → it gets traffic againAbout 10 seconds (1 passed check)About 10 seconds

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 HTTP 200 without a login. Return 200 only when the app can really serve requests.

Test the path from your computer before you rely on it:

curl -i http://203.0.113.10:8080/healthz

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

1

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.

2

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.”).

3

Edit the timing (optional)

Click Edit timing to see every field:

FieldDefaultAllowed
Check byPort is openPort is open or HTTP request
Path (HTTP)/Starts with /, up to 512 characters
Interval10 sec5–300 seconds
Timeout3 sec1–30 seconds, shorter than the interval
Unhealthy after3 fails1–10. Set 1 for an HTTP check.
Healthy after1 pass1–10

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.

4

Create

Finish the form and click Create Load Balancer.

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.

FieldMeaningAllowedDefault
protocolType of checkTCP or HTTPTCP
pathPath requested by an HTTP checkStarts with /, up to 512 characters/
interval_secondsTime between checks5–30010
timeout_secondsHow long to wait for an answer1–303
unhealthy_thresholdFailed checks before a target is taken out1–101 for HTTP (the only value supported for HTTP today), 3 for TCP
healthy_thresholdPassed checks before a target gets traffic again1–101

"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:

{
"name": "web",
"protocol": "HTTP",
"targets": [
{"kind": "vm", "resource_id": "vm-7f3c2d1e", "port": 8080},
{"kind": "vm", "resource_id": "vm-8a4d3e2f", "port": 8080}
],
"health_check": {
"protocol": "HTTP",
"path": "/healthz",
"interval_seconds": 10,
"timeout_seconds": 3
}
}

For a Network load balancer, use {"protocol": "TCP"}, which takes the defaults. See Create a load balancer for the full request.

Verify

  1. Stop the app on one VM, or make its health path return 503.
  2. 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.
  3. Send requests to the load balancer’s address. They should all reach the other VMs.
  4. Start the app again. About 10 seconds later, that VM gets traffic again.

Limits

SettingAllowedDefault
TypeTCP (Port is open) or HTTP (HTTP response)TCP
Interval5–300 seconds10 seconds
Timeout1–30 seconds, shorter than the interval3 seconds
Unhealthy threshold1–10 (1 for HTTP checks today)1 for HTTP, 3 for TCP
Healthy threshold1–101
PathUp to 512 characters, starting with //
Checks per target group1, applied to every target in the group—
UDP targetsNot health-checked—

Troubleshooting

You seeWhat it meansWhat to do
Requests fail right after you create the load balancerNo target passes the check yet, or the VMs are still startingWait about 20 seconds. If it continues, test the port or path with curl as above.
curl to the VM times outThe VM’s firewall group doesn’t accept the backend portAdd an accept rule for the port. See Create firewall rules. Check the firewall inside the VM too.
curl returns 301, 302, 401 or 404 on the health pathThe path redirects, needs a login, or doesn’t existUse a path that returns 200 directly, or switch to Port is open.
Every target fails an HTTP check on /The app doesn’t serve / with 200Set a real health path, or use Port is open.
An HTTP check has an unhealthy threshold above 1HTTP checks support only 1 todaySet Unhealthy after to 1, or leave unhealthy_threshold out.
The VM serves only TLS, and the HTTP check failsThere is no HTTPS checkUse Port is open.
A target flaps in and out of serviceThe app is slow to answer, or the timeout is too shortRaise the timeout (keep it shorter than the interval), or make the health path lighter.
”Check every 5 to 300 seconds”The interval is out of rangeEnter 5–300.
”The health check timeout must be 1 to 30 seconds”The timeout is out of rangeEnter 1–30.
”The health check timeout must be shorter than the interval”The timeout is equal to or longer than the intervalLower the timeout or raise the interval.
”Health check thresholds must be 1 to 10 checks”A threshold is out of rangeEnter 1–10.
”The health check path must start with / and contain at most 512 characters”The path is invalidEnter a path such as /healthz.