consul health checks
Consul supports five types of health checks - pick the one that fits your service.
-
http- GET request, expects 2xx -
tcp- opens a TCP connection, expects it to succeed -
grpc- sends a gRPC health check request -
script- runs a command, checks exit code -
ttl- service reports its own health by calling the API
http check
service {
name = "api"
port = "http"
check {
type = "http"
path = "/health"
interval = "10s"
timeout = "2s"
}
}
tcp check
check {
type = "tcp"
interval = "10s"
timeout = "2s"
}
grpc check
check {
type = "grpc"
interval = "10s"
timeout = "2s"
grpc_use_tls = false
}
Optionally target a specific service within the gRPC server:
check {
type = "grpc"
interval = "10s"
timeout = "2s"
# grpc_service = "my.ServiceName"
}
script check
check {
type = "script"
command = "/usr/local/bin/check-db.sh"
args = ["-timeout", "5s"]
interval = "30s"
timeout = "10s"
}
Exit codes: 0 = passing, 1 = warning, anything else = critical.
ttl check
Useful when the service knows its own state better than an external probe.
check {
type = "ttl"
ttl = "30s"
deregister_critical_service_after = "1m"
}
Update the status from inside the service:
curl -X PUT -d '{"Status": "passing"}' \
http://localhost:8500/v1/agent/check/update/<check_id>
Status values: passing, warning, critical.
multiple checks
service {
name = "worker"
port = "http"
check {
name = "http"
type = "http"
path = "/health"
interval = "10s"
timeout = "2s"
}
check {
name = "db connection"
type = "http"
path = "/health/db"
interval = "30s"
timeout = "5s"
deregister_critical_service_after = "2m"
}
}
Originally published at https://bard.sh/posts/consul_health_checks/
Top comments (0)