chiyt27
January 13, 2022, 10:53am
#1
Hi,
When I add args type of checks, then get error message when register service.
How can I fixed this error? thanks a lot.
$ consul services register demo-svc.json
Error registering service “demo-svc”: Unexpected response code: 400 (Invalid check: TTL must be > 0 for TTL checks)
demo-svc.json
{
"service": {
"name": "demo-svc",
"tags": [
"default"
],
"Address": "demo-service.default.svc.cluster.local",
"port": 8080,
"checks": [
{
"id": "demo-args",
"name": "args check",
"args": ["/tmp/test.sh"],
"interval": "10s",
"timeout": "1s"
}
]
}
}
/tmp/test.sh on demo-pod
#!/bin/bash
exit 0
helm-chart/values.yaml
server:
extraConfig: |
{
"enable_script_checks": true,
"enable_local_script_checks": true
}
blake
January 13, 2022, 5:16pm
#2
Hi @chiyt27 ,
This is a known bug in Consul. The problem is explained in detail at service script health checks not working · Issue #6923 · hashicorp/consul · GitHub .
As a workaround, you can register the service to Consul using the /agent/service/register
API.
demo-svc-api-reg.json
{
"name": "demo-svc",
"tags": [
"default"
],
"Address": "demo-service.default.svc.cluster.local",
"port": 8080,
"checks": [
{
"id": "demo-args",
"name": "args check",
"args": [
"/tmp/test.sh"
],
"interval": "10s",
"timeout": "1s"
}
]
}
$ curl --request PUT --data @demo-svc-api-reg.json http://127.0.0.1:8500/v1/agent/service/register
chiyt27
January 17, 2022, 5:26am
#3
Thanks for your reply!
I had registered my args-check success through by the API, but appear a new question.
Consul UI shows that args-check can’t find the file.
This is a picture about test.sh’s execute permission, content and using ‘exec’ to execute test.sh in pod.
demo-svc-api-reg.json
I remove the “id”: “demo-args” because the API returns ‘Request decode failed: json: unknown field “id”’.
{
"name": "demo-svc",
"tags": [
"default"
],
"Address": "demo-service.default.svc.cluster.local",
"port": 8080,
"checks": [
{
"name": "args check",
"args": [
"/tmp/test.sh"
],
"interval": "10s",
"timeout": "1s"
}
]
}
How to Consul agent find the script file and execute it?
chiyt27
February 7, 2022, 9:54am
#4
Hi @blake ,
I ref this post and try the pierresouchay’s suggest.
"args": ["/bin/ls", "/home"],
then I got the check output is
consul
Is the script not run in my demo-service?
blake
February 23, 2022, 10:53pm
#5
Hi @chiyt27 ,
My apologies for not clarifying this earlier. Consul health checks are run within the context of the agent that is executing them. Script checks, like the one you provided, will be run by the Consul client/server agent.
If you want to run a health check against your pod, you need to configure a network-level health check (i.e., TCP, HTTP, gRPC, etc) so that the agent can communicate with your target service.
1 Like