Skip to main content
https://travis-ci.org/btimby/django-k8s.png https://coveralls.io/repos/github/btimby/django-k8s/badge.svg?branch=master https://badge.fury.io/py/django-k8s.svg

django-k8s

Integration between Django and Kubernetes.

Caching

Service discovery for Memcached. Admittedly this will work with any service discovery that uses multiple A records for memcached servers. This allows the memcached client to properly distribute keys amongst memcached servers. AWS ElasticCache as well as Kubernetes and others are compatible with this scheme.

If an error is received when trying to access a memcached server, DNS resolution is performed again (refreshing server list). This allows memcached servers to be added or removed without restarting the application.

More information on this approach is provided below.

https://cloud.google.com/solutions/deploying-memcached-on-kubernetes-engine

Given Memcached deployed to Kubernetes with the following command:

helm install stable/memcached --name mycache --set replicaCount=3

You could configure your application like this:

CACHES = {
    'default': {
        'BACKEND': 'django_k8s.cache.backends.Memcached',
        'HOST': environ.get('DJANGO_CACHE_HOST', None),
    },
}

Migrations

One convenient way to handle Django migrations in Kubernetes is using a Job. However Django applications expect the database to be available and migrated on startup. Therefore some coordination is necessary. The application containers should wait for the migration job to complete before starting up.

This package provides a management command that polls the database to check for two conditions:

  1. That the database server is reachable.

  2. That all migrations have been applied.

It can optionally wait for both of these conditions to be true. An exit code of 0 indicates success. This management command could be part of your entrypoint, ensuring no Django application is started until these conditions are met.

This technique is compatible with systems other than Kubernetes, the author has used it with Docker Compose as well.

$ python manage.py checkmigrations
Migrations complete.

Release files for django-k8s 0.2.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-k8s 0.2.9
File Size Uploaded
django-k8s-0.2.9.tar.gz 7.0 kB Details

Release files / django-k8s-0.2.9.tar.gz

Download URL django-k8s-0.2.9.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
faa39fd91ff4b9c6d9841694754caba672f51c32ccad9acb9d94d475215d8308
BLAKE2b-256 checksum
How to use checksums
1783ba7091e0a0476a27ff09d0571eb7056411d42d6300a9d610aec8f5b1b0b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.7

Release history Release notifications | RSS feed

This release

0.2.9 This release

1 release file

0.2.7

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page