Skip to content

Django Helm Chart with Celery, Celery-Beat, Flower and Redis

License

Notifications You must be signed in to change notification settings

derkweijers/django-helm-chart

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Django Helm Chart

Django Helm Chart with Celery, Celery-Beat, Flower and Redis. The chart also includes deployments for Celery setup (Worker, Flower.

  • Deployment includes a multi container pod with Django and Caddy. Caddy is used as sidecar to serve the static files of backend. Caddyfile can be found here.

  • The chart includes Redis as an optional subchart.

  • The Deployment containers init containers for migrations and staticfiles.

This is my personal take on such a type of chart, thus I might not use the best practices or you might disagree with how I do things. Any and all feedback is greatly appreciated!

Deployment setup

Set values for Django backend on Deployment Section of values.yaml

Example:

replicaCount: 1
revisionHistoryLimit: 2
image:
  repository: ghcr.io/sanoguzhan/django-helm-test
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: "latest"
  containerPort: 8081
command: 'gunicorn blog.wsgi -b 0.0.0.0:8081'

Note: Set the command as a string instead of a list.

Static Files

Static files collect is done by initContainers.

  • staticfiles: Add command for Django to collect static files.
collect_static:
  enabled: false
  name: staticfiles
  command: "python3 manage.py collectstatic --noinput"

Static files and Media directories should be given under data:

data:
  staticfiles: "app/staticfiles/"
  data_media: "app/data_media/"

Paths should be relative to the working directory of main container. Static files are shared volume (emptyDir) between initContainer and Proxy container.

Migrations

Migrations are done with a Job. ServiceAccount, configMap and secret values are loaded before application container starts. Job is deleted after completion.

db_migrations:
  enabled: true
  name: db-migration
  command: "python3 manage.py migrate --noinput"
  resources: {}
  safeToEvict: true

ConfigMaps and Secrets

ConfigMaps and Secret values should be set under:

# Env ConfigMap values 
envConfigs: {}
# Enc Secret Values (Base64 encoded data)
envSecrets: {}

Celery Setup

Celery setup includes worker, flower and beat. Celery Beat is optional, set enabled to false if you want to exclude it. Flower includes ingress setup optionally.

celery:
# Celery Beat Values
  beat:
    enabled: true
    componentName: celery-beat
    command: 'celery -A blog.celery beat -l DEBUG'
    replicaCount: 1
    strategy: Recreate
# Celery Worker Settings  
  worker:
    componentName: celery-worker
    command: 'celery -A blog.celery worker -l DEBUG'
    replicaCount: 1
    strategy: RollingUpdate
# Celery Flower Settings
  flower:
    componentName: celery-flower
    command: 'celery -A blog.celery flower'
    replicaCount: 1
    strategy: RollingUpdate   
    service:
      type: ClusterIP
      port: 
        number: 5555
        name: flower
    ingress:
      enabled: false
      annotations: {}
      hosts:
        - host: example.com
          paths:
            - path: / 
              pathType: Prefix
      tls: []  

Redis

Redis is optional sub-chart, which could be disabled by setting enabled to false. Bitnami Redis Helm Chart is used, and version of the chart is given in the Chart.yaml file.

redis:
  enabled: true

Build chart dependency includes

helm dependency build ./django

Getting Started

Use the Github template

First, click the green Use this template button near the top of this page. This will take you to Github's 'Generate Repository' page. Fill in a repository name and short description, and click 'Create repository from template'. This will allow you to create a new repository in your Github account, prepopulated with the contents of this project.

Now you can clone the project locally and get to work!

git clone https://github.com/<user>/<your_new_repo>.git

About

Django Helm Chart with Celery, Celery-Beat, Flower and Redis

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Smarty 100.0%