DEV Community

Cover image for Django-probes: wait until database is ready - Probes for Docker and Kubernetes
Javid Mougamadou
Javid Mougamadou

Posted on

7 3

Django-probes: wait until database is ready - Probes for Docker and Kubernetes

Concepts

Provides a Django management command to check whether the primary database is ready to accept connections.

Run this command in a Kubernetes or OpenShift Init Container to make your Django application wait until the database is available (e.g. to run database migrations).

Installation

The easiest way to install django-probes is with pip

pip install django-probes
Enter fullscreen mode Exit fullscreen mode

Basic Usage

1) Add django-probes to your Django application:

INSTALLED_APPS = [
    ...
    'django_probes',
]
Enter fullscreen mode Exit fullscreen mode

2) Add an Init Container to your Kubernetes/OpenShift deployment configuration, which calls the wait_for_database management command:

- kind: Deployment
  apiVersion: apps/v1
  spec:
    template:
      spec:
        initContainers:
        - name: wait-for-database
          image: my-django-app:latest
          envFrom:
          - secretRef:
              name: django
          command: ['python', 'manage.py', 'wait_for_database']
Enter fullscreen mode Exit fullscreen mode

Links

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs