A healthcheck
This page adds healthchecks. A running container is not the same as a working one: nginx can be up and unable to serve, Redis can be up and still loading its data. A healthcheck is a test whose answer is what SHC means by ready. It is either a command the runtime runs inside the container or a probe the node sends to it from outside.
Read the deployment first. NO HEALTHCHECK counts the services SHC cannot
judge, because nothing tells it whether they work.
$ shc status -s guestbook...TENANT STACK ENVIRONMENT STATE SERVICES NODE LABELS NO HEALTHCHECKprod guestbook prod healthy 3/3 home01 app=/root/learn/guestbook environment=prod stack=guestbook tenant=prod 3...counter gets a command, redis-cli ping, which its image carries. web
and api get an SHC probe instead: ["SHC-HTTP", ":PORT/PATH"] has the
node ask the replica for that path and pass on any 2xx or 3xx answer, so
nothing has to be in the image. whoami’s image holds no shell and no client
at all, so for api the probe is the only check there is. interval is how
often a check runs, timeout how long one try may take, and retries how
many failures in a row make the container unhealthy. See
Health probes.
services: web: image: nginx:1.27-alpine expose: - "80" volumes: - ./site:/usr/share/nginx/html:ro healthcheck: test: ["SHC-HTTP", ":80/"] interval: 10s timeout: 3s retries: 3 x-shc-primary: true api: image: traefik/whoami:v1.10 command: ["--port", "8080", "--name", "guestbook-api"] expose: - "8080" healthcheck: test: ["SHC-HTTP", ":8080/"] interval: 10s timeout: 3s retries: 3 x-shc-path: /api x-shc-path-strip: true counter: image: redis:7-alpine command: ["redis-server", "--appendonly", "yes"] expose: - "6379" volumes: - data:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 3s retries: 12volumes: data:An update now waits until each check passes before it calls the deployment running, and fails if one never does.
$ shc update guestbook...$ shc status -s guestbook...TENANT STACK ENVIRONMENT STATE SERVICES NODE LABELSprod guestbook prod healthy 3/3 home01 app=/root/learn/guestbook environment=prod stack=guestbook tenant=prod...NO HEALTHCHECK is gone from the table: every service has a check now, and
every replica reads ready because its check passes, the node’s probes for
web and api and the runtime’s command for counter. The column shows
only while some service has none.
Next: A seed job.