====== Django on k8s ====== ===== - Sources ===== * https://medium.com/@markgituma/kubernetes-local-to-production-with-django-2-docker-and-minikube-ba843d858817 ==== - Complete tutorial ==== * https://medium.com/google-cloud/deploying-django-postgres-redis-containers-to-kubernetes-9ee28e7a146 * https://medium.com/google-cloud/deploying-django-postgres-and-redis-containers-to-kubernetes-part-2-b287f7970a33#.vjwzjntcq * Other: https://medium.com/@markgituma/kubernetes-local-to-production-with-django-2-docker-and-minikube-ba843d858817 ===== - App deployment ===== ===== - Postgres DB deployment ===== * https://portworx.com/postgres-kubernetes/ * https://severalnines.com/database-blog/using-kubernetes-deploy-postgresql ==== - Troubleshooting ==== * https://github.com/kubernetes/kubernetes/issues/70241#issuecomment-434242145 * check yaml syntax (copy paste error): https://github.com/adrienverge/yamllint#installation ===== - Django migration ===== * https://medium.com/@markgituma/kubernetes-local-to-production-with-django-3-postgres-with-migrations-on-minikube-31f2baa8926e ===== - Quick start & Operation ===== Follow the next sections for details of the setup process. This section details the operator guide. ==== - Deploy from source ==== Checkout source git clone git@bitbucket.org:thuydang/vfossorg_pj.git Build db, app, or both: make build-db make build-app # both make build Deploy with k8s kubectl apply -f ./kubernetes/postgres kubectl apply -f ./kubernetes/django ==== - Initialize Django app ==== Django version 2.1.15 Django-cms version 3.6.0 === - Migration === Migrations can also be executed from the shell of a running container using the kubectl exec command. In order to run the migrations, we need to get the name of the running pod of interest by: kubectl get pods Once the pod name has been found, the migrations can be run by: kubectl exec -- python /app/manage.py migrate === - Superuser === Execute pods: kubectl exec -it -n vfoss vfoss-org-app-7bbd4ff7db-bpxx8 -- /bin/bash ./manage.py createsuperuser user: admin password: a1d3m7 === - Serving statics files === This removes error with large search icon, etc. ./manage.py collectstatic ==== - Update Deployment ==== === - Deploy latest image (not working) === * https://medium.com/google-cloud/deploying-django-postgres-and-redis-containers-to-kubernetes-part-2-b287f7970a33#.vjwzjntcq If you weren’t updating the Replication Controller definition and wanted to just change the image, the safest way is a rolling-update, which will spin up 1 new container at a time and only keep going if the new containers successfully start. kubectl rolling-update frontend \ --image=gcr.io/${GCLOUD_PROJECT}/guestbook If, like me, you like to live dangerously, and don’t mind a little downtime you can instead edit the frontend.yaml file to point to your new image, scale the replication controller down to 0 (killing all your pods) and then scale it back up. kubectl scale replicaset -n vfoss vfoss-org-app-7bbd4ff7db --replicas=0# kill your pods kubectl scale replicaset -n vfoss vfoss-org-app-7bbd4ff7db --replicas=1 # new image === - Deploy image with latest tag === * https://elatov.github.io/2018/07/update-a-kubernetes-deployment/ *