This simple web application extends Django Cookiecutter to deploy the application in microservices manner. Moreover, Kubernetes Manifests are added to orchestrate how the applications communicate with each other and deploy the production in Azure Kubernetes Cluster.
The steps for reproducing the project from fresh Django Cookiecutter project can be by going through the following chain of tutorials:
- Hands-on Day 1 and Day 2 Operations in Kubernetes using Django and AKS - Part 1: Setup the production cluster and private container repository.
- Hands-on Day 1 and Day 2 Operations in Kubernetes using Django and AKS - Part 2: Discuss's how to manage the application's environment variables and configurations as well as how to set up the volume profiles that will be mounted onto the containers.
- Hands-on Day 1 and Day 2 Operations in Kubernetes using Django and AKS - Part 3: Deploy, monitor and define update strategies for the services including setting up Traefik as Ingress Controller
- Hands-on Day 1 and Day 2 Operations in Kubernetes using Django and AKS - Part 4: DevOps and Auto Deployment using Github Actions
The application consists of the following components:
- Django: web framework.
- Redis: Queue System.
- Celeryworker: Performing background tasks.
- Celerybeat: Perform scheduled tasks.
- Postgres: Database.
The application has simple functionality for the purpose of demonstrating communication and deployment of the services in the cluster. In the admin panel, you are capable of inserting an image with caption and title. Once the image is created, a task will be escalated to the queue to resize the image. If any of the workers is free, then it will overtake the task and process it.
To deploy the application in kubernetes cluster where the communication between the microservices are done via a shared volume. Moreover, once an image in Gallery is created, Django will upload the image in the shared folder, and the worker assigned to the task can get the image from the shared folder, resize it and save it in the same place.
With that, we remove the overhead of pushing the images in the network between the services, this technique can be very helpful for uploading and sharing huge files.
For local development, you can run the application with the following command:
docker-compose -f local.yml up --build
To create a superuser and access to the admin dashboard:
docker-compose -f local.yml run --rm django python manage.py createsuperuser
Further information can be found in cookiecutter django documentation.
There are two changes you need to apply:
- Rename
pm.yaml.example
incompose/kubernetes/secrets/
topm.yaml
and fill in the secrets. - Set the URL to where you want to upload the docker images. by renaming
.env.example
and assign value toCR_URL
.
Then, build the production images:
docker-compose -f production.yml build
and push them to your repository:
docker-compose -f production.yml push
In kubernetes you have to create the configmaps, secrets and Persistent volumes:
kubectl apply -f compose/kubernetes/namespaces/production.yaml
kubectl apply -f compose/kubernetes/configmaps/.
kubectl apply -f compose/kubernetes/secrets/.
kubectl apply -f compose/kubernetes/persistence_volumes/storage_classes/.
kubectl apply -f compose/kubernetes/persistence_volumes/.
Add the correct URL (the one you assigned to CR_URL
) image in kubernetes manifests.
Then, create the application in the cluster:
kubectl apply -f compose/kubernetes/.
To add traefik as ingress controller:
- create traefik services:
kubectl apply -f compose/kubernetes/ingress/traefik-service.yaml
- Get the external IP address and assign a domain name to the IP address.
- Make sure traefik's ConfigMaps are created:
kubectl apply -f compose/kubernetes/configmaps/.
- After DNS records have been updated, create the traefik controller:
kubectl apply -f compose/kubernetes/ingress/traefik-controller.yaml