API Reference
The following is an autodoc generated reference from the django-kubernetes code base. It is probably the most up to date documentation regarding the functionality of the various modules. If there is a conflict between the documentation and this reference; then this reference should be the canonical truth.
Please note that if you do detect such a discrepancy, open an issue so we can fix it as soon as possible!
Middleware
- class djk8s.middleware.ProbeMiddleware(get_response)
Bases:
objectThis middleware handles Kubernetes liveness, readiness, and health probes. Middleware is used instead of a view to ensure that there are no database or cache calls that might cause a 500 error or prevent an actual health check. If the middleware detects an unhealthy or unready state, it will return a 503 error.
If you’re not concerned about database usage or cache calls, you can use the provided probe views in djk8s.views instead.
- health(request)
Always returns a 200 Ok response. If the Django server can handle requests, then it is healthy and live.
- ready(request)
Connects to each database and performs a generic SQL query to check that the database connection is available and responding to requests. Connects to any caches and calls get_stats to check if the cache is online.
Views
- class djk8s.views.LivenessView(**kwargs)
Bases:
ViewA view that always returns a 200 OK response for liveness and health check probes.
- get(*args, **kwargs)
- class djk8s.views.ReadinessView(**kwargs)
Bases:
ViewA view that checks readiness using configured probes. If any probe raises NotReady, it returns a 503 Service Unavailable response. Otherwise it returns a 200 OK.
- classmethod as_view(**kwargs)
Override the as_view method to ensure probes are initialized.
- get(request, *args, **kwargs)
Check readiness by executing all configured probes. If any probe is not ready, return a 503 Service Unavailable response.
- probes
Decorator that converts a method with a single cls argument into a property that can be accessed directly from the class.
Probes
- class djk8s.probes.DatabaseProbe
Bases:
ReadinessProbe
- class djk8s.probes.MemcachedProbe
Bases:
ReadinessProbe