Skip to main content

Integration between Django and Kubernetes.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-k8s-0.2.5.tar.gz (3.2 kB view details)

Uploaded Source

File details

Details for the file django-k8s-0.2.5.tar.gz.

File metadata

  • Download URL: django-k8s-0.2.5.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-k8s-0.2.5.tar.gz
Algorithm Hash digest
SHA256 ffc92195ace744ed5db96b9b1b5ee7e8982c3d41b8cabf32b666a2d1dcdaab1e
MD5 3ab10af184edff00cbe81e8f9de94ab0
BLAKE2b-256 206d3fd610546e702c22428a94ec12215856f0bbd74273b29f479b6c29c89203

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page