Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Load Balancing Health Checks

When configuring load balancing, you specify a health check object to use to determine the health of your instances. Health check objects are global resources that can be associated with multiple configurations.

Overview

Health checks ensure that Compute Engine forwards new connections only to instances that are up and ready to receive them. Compute Engine sends health check requests to each instance at the specified frequency; once an instance exceeds its allowed number of health check failures, it is removed from the pool of eligible instances. It will continue to receive packets for its existing connections until they're terminated or the instance terminates; this allows instances to shut down gracefully without abruptly breaking TCP connections.

The health check continues to query unhealthy instances, and returns an instance to the pool once the specified number of successful checks is exceeded.

For a health-check to be deemed successful, the backend must return a valid HTTP response with code 200 and close the connection normally within the timeoutSec period.

No notifications are sent by the health check service.

Health checks are required for HTTP load balancing. Health checks are optional for network load balancing, but become required if you are using backup target pools in your network load balancing configuration.

Create a health check

Before you can associate a health check with your load balancing configuration, you must first create the health check resource.

To create a health check object with gcloud compute , use the http-health-checks create sub-command:

$ gcloud gcloud compute http-health-checks create HEALTH_CHECK
    [--check-interval CHECK_INTERVAL; default="5s"]
    [--description DESCRIPTION]
    [--healthy-threshold HEALTHY_THRESHOLD; default="2"]
    [--host HOST]
    [--port PORT; default="80"]
    [--request-path REQUEST_PATH; default="/"]
    [--timeout TIMEOUT; default="5s"]
    [--unhealthy-threshold UNHEALTHY_THRESHOLD; default="2"]

For HTTP load balancing, the value of --port must be the same port as is listed in your backend service.

To make a request to the API, send a POST request to the following URI:

POST http://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/httpHealthChecks

{
  "name" : NAME
}

The body of your request must contain, at a minimum, the name field.

Associate the health check with your configuration

Creating a health check resource does not automatically apply the health check resource to your configuration. After you add a health check, you must associate it with a target pool or backend service before it can perform health checking.

It is not possible to define different health check parameters for each instance. You can only define health check parameters that apply to all instances in that target pool or backend service.

Network load balancing

You can add a health check to an existing target pool, or to a new target pool. This example adds the health check object to an existing target pool:

$ gcloud compute target-pools add-health-check TARGET_POOL \
  --health-check HEALTH_CHECK \
  --region=REGION

HTTP load balancing

When you create your backend service object, you must specify a health check object. See Updating a backend service for details.

Update firewall rules

Health check requests must be able to connect to the health check URLs on each of your instances. Ensure that the firewall rules are in place to allow these connections. For HTTP load balancing, the health check requests come from addresses in the range 130.211.0.0/22 . For network load balancing, the health check requests come from 169.254.169.254 .

Updating health checks

To update the properties of an existing health check with gcloud compute , use the http-health-checks update sub-command. The values of your request will update the existing values of the health check.

$ gcloud compute http-health-checks update HEALTH_CHECK
    [--check-interval CHECK_INTERVAL]
    [--description DESCRIPTION]
    [--healthy-threshold HEALTHY_THRESHOLD]
    [--host HOST]
    [--port PORT]
    [--request-path REQUEST_PATH]
    [--timeout TIMEOUT]
    [--unhealthy-threshold UNHEALTHY_THRESHOLD]

In the API, you can choose to update your health check using the standard PUT request, or use PATCH to partially update your health. PATCH will only update the fields that you specify.

https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/httpHealthChecks/<health-check>

Your request body should contain your desired fields and values to update for this health check.

Listing health checks

To list health checks with gcloud compute , use the http-health-checks list sub-command:

$ gcloud compute http-health-checks list

In the API, make a GET request to the following URI:

http://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/httpHealthChecks

Getting a health check

To get information about a specific health check with gcloud compute , use the http-health-checks describe sub-command:

$ gcloud compute http-health-checks describe [HEALTH_CHECK]

If the name of the health check is omitted, verbose information is returned for all existing health checks.

In the API, make a GET request to the following URI:

http://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/httpHealthChecks/<health-check>

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.