Template solution for Django Web App with:
- Django v.4.0.x
- Bootstrap v.5
- SQLite
pip install -r requirements.txt
Create Application database and data definitions:
python manage.py makemigrations
python manage.py migrate
If not already done, create super-user with
python manage.py createsuperuser
If unsure, try with "admin/admin"
Run locally within Django sandbox:
./run.sh
docker build --platform linux/amd64 -t smart-django:x .
docker run -p 8080:8080 smart-django:1
You may use any Kubernetes cluster, or install 'minikube' locally:
https://minikube.sigs.k8s.io/docs/start/
then
minikube start
Setup PostgreSQL pod:
kubectl apply -f k8s/postgres/volume.yaml
kubectl apply -f k8s/postgres/volume_claim.yaml
kubectl apply -f k8s/postgres/secrets.yaml
kubectl apply -f k8s/postgres/deployment.yaml
kubectl apply -f k8s/postgres/service.yaml
Setup Django pod:
docker build -t smart-django:1 .
Now you should push this image on some Container Registry. For your convenience, this image has been already pushed to Docker Hub, so you may skip this step.
docker tag smart-django:1 <your-registry>/smart-django:k8s
docker push <your-registry>/smartdjango:k8s
Now you can deploy the Django pod:
kubectl apply -f k8s/django/deployment.yaml
kubectl apply -f k8s/django/service.yaml
See django logs with:
kubectl logs -f django-<pod-id>
kubectl delete -f k8s/django/service.yaml
kubectl delete -f k8s/django/deployment.yaml
kubectl delete -f k8s/postgres/service.yaml
kubectl delete -f k8s/postgres/deployment.yaml
kubectl delete -f k8s/postgres/secrets.yaml
kubectl delete -f k8s/postgres/volume_claim.yaml
kubectl delete -f k8s/postgres/volume.yaml
It is recommended, if you are using minikube, to remove all resources:
minikube delete
minikube service django-service
kubectl exec -it postgres-<pod-id> -- psql -U django -d postgres
kubectl exec -it django-<pod-id> -- /bin/bash