django-probes
django-probes copied to clipboard
Add middleware or similar for Kubernetes probes
As of today, this Django app only provides a way to ensure that a database, configured in your Django project, is reachable. The main use case for this is a Kubernetes Init Container.
Health checks
For the health checks after the startup phase, we usually suggest to implement the Kubernetes probes with the least impact that technically makes sense. For Python application running uWSGI this is a check on the socket, e.g.
containers:
- name: django
ports:
- name: uwsgi
containerPort: 8000
livenessProbe:
tcpSocket:
port: uwsgi
initialDelaySeconds: 13
readinessProbe:
tcpSocket:
port: uwsgi
initialDelaySeconds: 9
However, if someone for some specific reason wanted to do checks deeper into the Django application stack we may need to provide an appropriate way to call the application in a way that consumes few resources. (A management command will probably not do for this use case.)
Other background reading
- Kubernetes Health Checks in Django (@ianlewis, May 2017)
- How to Avoid Shooting Yourself in the Foot (@breckcs, Nov 2018)