/demo_django

Transferred from my other account

Primary LanguagePython

What is this

This is a demo django project using docker-compose and kubernetes.

Prerequisites

  • git
  • minikube
  • kubectl
  • python 3.x
  • Django 3.0.2
  • gunicorn 0.0.4

How to run

  1. clone this git repo $ git clone git@github.com:KaizenPikachu/demo_django.git
  2. kubectl apply - django-deployment.yaml
  3. Create loadbalancer to be able to access the app $ kubectl expose deployment django --type=LoadBalancer --port=8000
  4. Check status that everything is created correctly $ kubectl get all
  5. Make service accessable locally through minikube. $ minikube service django

How this demo/test was made

  1. Django project was generated through pycharm.
  2. Implemented a django app structure, a webserver (gunicorn), some simple content.
  3. Implemented a Dockerfile to be able to create docker containers.
  4. Implemented docker-compose to more easily be able to run the project locally and as a preparation for later steps.
  5. Build and push containers to dockerhub
    • docker build -t maja39/django-demo:0.2 .
    • docker push maja39/django-demo:0.2
  6. Converted docker-compose to kubernetes charts using Kompose. https://www.digitalocean.com/community/tutorials/how-to-migrate-a-docker-compose-workflow-to-kubernetes
  • The version of generated was buggy, so I had to convert the yaml file to apiVersion apps/v1
  • $ kubectl convert -f django-deployment.yaml --output-version apps/v1
  • Note the convert functionality as of now is deprecated, but it will probably only change the way of conversion.
  1. Write the docker-hub path for the image in the yaml file. In this demo, the docker-hub image is public, but this can obviously be made private.
  2. Deploy it to kubernetes locally.
  • kubectl apply - django-deployment.yaml
  1. Add a loadbalancer to open up access to the webserver
  • $ kubectl expose deployment django --type=LoadBalancer --port=8000
  1. Expose the service through local routing using minikube
  • minikube service django

Notes

The local-config.map got generated as a response to the empty .env folder, which I created as a placeholder for when environment variables will be needed. Since it is empty as of now, it don't need to be applied.

minikube ssh top shift m ctrl c ctrl d