Health checks configuration in GCP - Commands & Configuration
apiVersion: compute.cnrm.cloud.google.com/v1beta1 kind: ComputeHealthCheck metadata: name: example-health-check spec: checkIntervalSec: 10 timeoutSec: 5 healthyThreshold: 3 unhealthyThreshold: 3 httpHealthCheck: port: 8080 requestPath: /health type: HTTP
This file creates a health check resource in Google Cloud.
checkIntervalSec sets how often Google Cloud checks your app.
timeoutSec is how long it waits for a response.
healthyThreshold is how many successful checks in a row make the app healthy.
unhealthyThreshold is how many failed checks in a row make the app unhealthy.
httpHealthCheck defines the port and path to check your app's health.
type is the protocol used for the check.
gcloud deployment-manager deployments create example-health-check --config health-check.yaml
--config - Specifies the configuration file to use for deployment.gcloud compute health-checks describe example-health-check
gcloud compute backend-services update example-backend-service --health-checks example-health-check --global
--health-checks - Specifies which health check to attach.--global - Indicates the backend service is global.gcloud compute backend-services get-health example-backend-service --global
--global - Indicates the backend service is global.If you remember nothing else from this pattern, remember: health checks tell Google Cloud if your app is working so it can manage traffic and restarts automatically.
Practice
What is the main purpose of a health check in Google Cloud Platform?
Solution
Step 1: Understand health check function
Health checks regularly test if servers respond correctly to requests.Step 2: Identify main purpose
This helps detect unhealthy servers so they can be fixed or replaced.Final Answer:
To monitor if servers are working properly -> Option BQuick Check:
Health check = Monitor server health [OK]
- Confusing health checks with backups
- Thinking health checks increase speed
- Assuming health checks add storage
Which of the following is the correct way to specify a TCP health check in a Google Cloud load balancer configuration?
{
"type": "TCP",
"port": 80,
"checkIntervalSec": 5
}Solution
Step 1: Identify correct health check type
TCP health checks use "type": "TCP" to test TCP connections on the port.Step 2: Match correct JSON syntax
The example matches the correct syntax with type TCP, port 80, and interval 5 seconds.Final Answer:
{ "type": "TCP", "port": 80, "checkIntervalSec": 5 } -> Option AQuick Check:
TCP type with port 80 = { "type": "TCP", "port": 80, "checkIntervalSec": 5 } [OK]
- Using HTTP instead of TCP for TCP check
- Using unsupported types like UDP or ICMP
- Wrong JSON syntax or missing fields
Given this health check configuration snippet, what will happen if the server does not respond within 10 seconds?
{
"type": "HTTP",
"port": 8080,
"timeoutSec": 10,
"unhealthyThreshold": 3
}Solution
Step 1: Understand timeout and threshold
The timeoutSec of 10 means the check waits 10 seconds for a response before failing.Step 2: Apply unhealthyThreshold logic
The server must fail 3 consecutive checks to be marked unhealthy.Final Answer:
The server is marked unhealthy after 3 failed checks -> Option AQuick Check:
Timeout + 3 failures = unhealthy after 3 tries [OK]
- Thinking server is removed immediately after 1 failure
- Ignoring unhealthyThreshold setting
- Assuming server restarts automatically
Identify the error in this health check configuration snippet:
{
"type": "HTTP",
"port": "eighty",
"requestPath": "/health",
"checkIntervalSec": 5
}Solution
Step 1: Check port field type
The port value is "eighty" as a string, but it must be a numeric value like 80.Step 2: Validate other fields
requestPath is valid for HTTP, checkIntervalSec can be 5, and type "HTTP" is correct.Final Answer:
Port must be a number, not a string -> Option CQuick Check:
Port number must be numeric [OK]
- Using string instead of number for port
- Thinking requestPath is invalid for HTTP
- Assuming checkIntervalSec minimum is 10
You want to configure a health check that verifies your web app responds with HTTP 200 on path /status every 15 seconds, and marks the server unhealthy after 2 failures. Which configuration is correct?
Solution
Step 1: Match health check type and path
The app uses HTTP checks on path "/status" so type must be "HTTP" and requestPath "/status".Step 2: Verify timing and thresholds
Check interval is 15 seconds and unhealthyThreshold is 2, matching requirements.Step 3: Confirm port number
Port 80 is standard for HTTP, so it fits the web app default.Final Answer:
{ "type": "HTTP", "port": 80, "requestPath": "/status", "checkIntervalSec": 15, "unhealthyThreshold": 2 } -> Option DQuick Check:
HTTP + /status + 15s + 2 failures = { "type": "HTTP", "port": 80, "requestPath": "/status", "checkIntervalSec": 15, "unhealthyThreshold": 2 } [OK]
- Using TCP type for HTTP path
- Wrong requestPath or port
- Incorrect checkIntervalSec or unhealthyThreshold
Ready to prove it?
Pass the test and this pattern moves unknown
