Flask-Healthz
Define endpoints in your Flask application that Kubernetes can use as liveness and readiness probes.
Setting it up
Blueprint
Register the blueprint on your Flask application:
from flask import Flask
from flask_healthz import healthz
app = Flask(__name__)
app.register_blueprint(healthz, url_prefix="/healthz")
Define the functions you want to use to check health. To signal an error, raise flask_healthz.HealthError.
from flask_healthz import HealthError
def liveness():
pass
def readiness():
try:
connect_database()
except Exception:
raise HealthError("Can't connect to the database")
Now point to those functions in the Flask configuration:
HEALTHZ = {
"live": "yourapp.checks.liveness",
"ready": "yourapp.checks.readiness",
}
It is possible to directly set callables in the configuration, so you could write something like:
HEALTHZ = {
"live": lambda: None,
}
Check that the endpoints actually work:
$ curl http://localhost/yourapp/healthz/live
{"status": 200, "title": "OK"}
$ curl http://localhost/yourapp/healthz/ready
{"status": 200, "title": "OK"}
Now your can configure Kubernetes or OpenShift to check for those endpoints.
Extension
You can also use the provided Flask extension to register the healthz blueprint:
from flask import Flask
from flask_healthz import Healthz
app = Flask(__name__)
Healthz(app)
The rest of the configuration is identical.
The extension has an additional option, no_log, that can disable logging of the HTTP requests
handled by your healthz endpoints, to avoid cluttering your web log files with automated requests.
At the moment, only the gunicorn web server is supported.
Healthz(app, no_log=True)
Examples
Here's an example of how you could use flask-healthz in OpenShift's deploymentconfig:
kind: DeploymentConfig
spec:
[...]
template:
[...]
spec:
containers:
- name: yourapp
[...]
livenessProbe:
httpGet:
path: /healthz/live
port: 8080
initialDelaySeconds: 5
timeoutSeconds: 1
readinessProbe:
httpGet:
path: /healthz/ready
port: 8080
initialDelaySeconds: 5
timeoutSeconds: 1
Some projects that have setup flask-healthz:
- Noggin: https://github.com/fedora-infra/noggin/pull/287
- FASJSON: https://github.com/fedora-infra/fasjson/pull/81
License
Copyright 2020-2021 Red Hat
Flask-Healthz is licensed under the same license as Flask itself: BSD 3-clause.
Metadata
Release files for flask-healthz 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flask_healthz-1.0.1.tar.gz | 5.3 kB | Without provenance | Details for flask_healthz-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flask_healthz-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for flask_healthz-1.0.1-py3-none-any.whl |
Total release size: 12.8 kB
Release files / flask_healthz-1.0.1.tar.gz
| Download URL | flask_healthz-1.0.1.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b25bfd8606950a77632925cfbbf19cac20650be51fc0efbe78c387e559e2541
|
|
BLAKE2b-256 checksum How to use checksums |
6ea34566a5059d8ac22a8be35b34f22b0e6c02997a6e7c85cddcbf4f49f303a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Release files / flask_healthz-1.0.1-py3-none-any.whl
| Download URL | flask_healthz-1.0.1-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
208e1f35d12d70bca623ac2dd9de17813c397f9f0a0c09aa746b4a543c75615d
|
|
BLAKE2b-256 checksum How to use checksums |
fd4290a825d7f90332b298c670fa78adfad4c401a3dcab41873b8f3e096ad958
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Security for flask-healthz 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.