Health & Readiness¶
On this page you will learn the difference between the health check and the readiness probe of a Workload, and how to set them up in the app.yaml.
Available Guides¶
- Declare the Probes in app.yaml
- Choose the Check Method
- Tune the Timing
- Example: A Workload With a Slow Startup
- Make Your Application Answer the Probes
Overview¶
Two Probes, Two Questions¶
A running Workload can be asked two different questions. Each question has its own probe.
| Probe | The question | What happens when it fails | Use it for |
|---|---|---|---|
| Liveness (health check) | Is the Workload still running? | The Workload is restarted. | Finding a process that is frozen or stuck. |
| Readiness | Is the Workload ready to serve? | The Workload is marked as not ready. It is not restarted. | Workloads that take time to start, for example loading a machine learning model, warming a cache or waiting for other connections. |
Both probes are optional, and you can use one, both or neither.
Why You Need Readiness¶
With only a liveness probe, you have to make a bad choice.
- If the probe is lenient enough to survive a slow startup, it also hides real problems, because a frozen Workload is found much later.
- If the probe is strict enough to find a frozen Workload quickly, it also restarts a healthy Workload that is only warming up.
A readiness probe removes the choice. Liveness answers "restart me", and readiness answers "do not rely on me yet".
Good to Know¶
- Readiness is optional. If you do not declare it, your Workload behaves exactly as before.
- It works wherever Workloads run with a liveness probe today, in the cloud and on the edge.
- The probes use the same mechanism as the Kubernetes liveness and readiness probes. You can read more on the Kubernetes Website.
- Startup probes are not supported. For a very slow startup, use an Initial Delay on the readiness probe.
Guides¶
Declare the Probes in app.yaml¶
Add the probes to the health_check setting in the system section of the app.yaml. This sets the default for every deployment of the Application.
You can change these defaults when you deploy a Workload, in the Advanced section.
Choose the Check Method¶
Each probe has a type that chooses the check method. The settings of the method are in the block with the same name as the type.
type |
Block | What it does | Settings |
|---|---|---|---|
http_get |
http_get |
Sends an HTTP GET request to your Workload. | port (required), path, scheme (http or https) and http_headers. |
tcp_socket |
tcp_socket |
Checks that a TCP port is open. | port (required). |
exec |
exec |
Runs a command inside the container. An exit code of 0 is healthy. | command (required), a list of strings. |
On a readiness probe, type is required and the block that matches the type must be present.
| app.yaml Examples | |
|---|---|
Note
The port and path belong inside the block, for example http_get, and not directly on the probe.
Tune the Timing¶
The timing settings are on the probe itself, next to type.
| Setting | Description | Liveness default | Readiness default |
|---|---|---|---|
initial_delay_seconds |
Seconds to wait before the first check. | 1 | 0 |
period_seconds |
How often the check runs, in seconds. | 10 | 10 |
timeout_seconds |
Seconds before the check times out. | 1 | 1 |
failure_threshold |
Number of failures in a row before the probe fails. | 3 | 3 |
success_threshold |
Number of successes in a row before the Workload is ready. | Not available | 1 |
The values period_seconds, timeout_seconds, failure_threshold and success_threshold must be 1 or more. initial_delay_seconds can be 0 or more.
success_threshold is only for readiness. A liveness probe is happy with one success.
Example: A Workload With a Slow Startup¶
An Application loads a machine learning model when it starts. This takes about 60 seconds. Afterwards it answers requests quickly.
With only a liveness probe
| app.yaml Example | |
|---|---|
The probe checks every 10 seconds and fails after 3 failures, so the Workload is restarted after about 30 seconds. The model needs 60 seconds, so the Workload is restarted again and again and never finishes starting.
To fix it you must make the probe lenient, for example failure_threshold: 10. Now the Workload starts, but a frozen Workload is also only found after 100 seconds.
With a liveness and a readiness probe
| app.yaml Example | |
|---|---|
/health/liveanswers as soon as the process is running, so the liveness probe stays strict and still finds a frozen Workload in about 30 seconds./health/readyonly answers after the model is loaded. Until then the Workload is marked as not ready, and it is not restarted.
Make Your Application Answer the Probes¶
The probes only work if your Application answers them.
- For
http_get, the Application must serve thepathon theportand answer with a successful response when the check passes. - For
tcp_socket, the Application must listen on theport. - For
exec, thecommandmust exit with 0 when the check passes.
Warning
Use different endpoints for liveness and readiness. If they share one endpoint, they fail together and the Workload is restarted, which is what readiness is meant to avoid.