Liveness and health probes
pdelaby opened this issue · 1 comments
As we use imgpush with Docker, it could be interesting to add liveness and readiness endpoints (for Docker Healthcheck and/or Kubernetes probes.
Liveness
Usually a simple GET request on a specific endpoint does the trick. I would suggest creating a /liveness
endpoint that just returns 200 OK
.
Something like
@app.route("/liveness", methods=["GET"])
def liveness():
return Response(status=200)
For the container to be able to query it, the image woud need to install curl
in order to perform the check :
- either directly in the Dockerfile : (not yet supported by Kubernetes I think)
HEALTHCHECK CMD curl http://localhost:5000/liveness -s -f -o /dev/null || exit 1
- or in the docker-compose
healthcheck:
start_period: 0s
test: ['CMD-SHELL', 'curl localhost:5000/liveness -s -f -o /dev/null || exit 1']
interval: 30s
Readiness
For this one, I'm more mitigated. I really like the Spring Health Actuator ( see example here ) that check evyrthing the app depends on. In this case, maybe the disk space ?
The /health
endpoint coud return something like
{
"status":"UP",
"diskspace":{
"status":"UP",
"free":912412675,
"treshold":10485260,
"total":5512411672
}
}
And diskspace woud be DOWN when the free space is below the diskspace_threshold setting.
However, this is not a free operation (that's why I suggest to use /liveness
for Docker health), and probably needs to be cached and/or secured. The lib py-healthcheck
does the caching job pretty well, and the endpoint coud be hidden from public access, but it's a more sensitive issue than the readiness endpoint.
What do you think ?
Sounds useful. I'm not too familiar with kubernetes probes but if you are and you need this feature, feel free to open up a PR and i'll have a look :)