Giter VIP home page Giter VIP logo

codingforentrepreneurs / django-kubernetes Goto Github PK

View Code? Open in Web Editor NEW
141.0 6.0 123.0 48 KB

Learn how to deploy a docker-based Django application into a Kubernetes cluster into production on DigitalOcean.

Home Page: https://www.codingforentrepreneurs.com/projects/django-kubernetes

License: MIT License

Python 92.65% Dockerfile 2.55% Shell 4.80%
django kubernetes k8s digitalocean digitalocean-kubernetes doks

django-kubernetes's Introduction

Django & Kubernetes Logo

Django & Kubernetes

Learn how to deploy a production-ready Django application into a Kubernetes cluster.

Kubernetes is a tool to manage containers. This type of management is called orchestration because it does more than just manage the containers such as it will scale up and scale down resources as needed (among many other things).

Since Kubernetes is a massive tool, we're going to be covering a practical implementation using a Docker-based Django application.

Django is a way to build web applications rapidly using Python. There are many ways to get Django into production so the question is why use K8S at all? There's many reasons we'll cover throughout this series but here are a few:

  • Gracefully deploy Docker-based Django projects
  • Scale up (or scale down) your web apps with ease
  • Use a few or a lot of microservices internally or externally
  • Self-heal when services go down
  • Simplify app deployment (after initial configuration)
  • Streamline your backend Infrastructure (provision virtual machines and let k8s do the rest)

Kubernetes can do a lot which makes it a great tool to learn but also a daunting one at that. To make it more approachable here's what we'll be doing:

  • Start a Python Virtual Environment
  • Create a bare bones production-ready Django project
  • Create a Dockerfile to describe our environment (much like this blog post)
  • Use a managed Database service from DitgitalOcean
  • Install Kubernetes locally
  • Start a Kubernetes Cluster on DigitalOcean
  • Provision a Deployment and Service for our Django project
  • Implement Github Action Workflows to automate future deployments

References

We have partnered with DigitalOcean to bring you this series. Sign up for an account when you're ready to get started with this series.

Cloning this Repo?

Make sure you create web/.env and fill in the following variables:

DEBUG=1
REGION=texas
DJANGO_SUPERUSER_USERNAME=admin
DJANGO_SUPERUSER_PASSWORD=mydjangopw
[email protected]
DJANGO_SECRET_KEY=fix_this_later

POSTGRES_READY=0
POSTGRES_DB=dockerdc
POSTGRES_PASSWORD=mysecretpassword
POSTGRES_USER=myuser
POSTGRES_HOST=localhost
POSTGRES_PORT=5434

REDIS_HOST=redis_db
REDIS_PORT=6388

If you change POSTGRES_PORT or REDIS_PORT be sure to update those values in docker-compose.yaml

Once you have the above .env file, navigate to your project root (right where docker-compose.yaml is) and run:

docker compose up -d

This will create a postgresql database that's running in the background for you. To bring this database down just run:

docker compose down

The data in the database will be persistent so you can run docker compose up -d again with confidence.

Also in the root of your project:

python3.9 -m venv venv
source venv/bin/activate
pip install -r web/requirements.txt

This will ensure your Django project is ready to be used locally.

django-kubernetes's People

Contributors

codingforentrepreneurs avatar teamcfe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

django-kubernetes's Issues

Github Secrets

Hey there, how are you?

First of all, what an amazing project and tutorial you did. Really, this is insanely helpfull. Thank you for that!

I have a question about the Github actions secrets. Let's assume that I'm the owner of a project working with some other devs (collaborators). I don't want to put all envvars on Github actions secrets because every collaborator can access them.

Is there any tip or thoughts on how make this happen?

Thanks and congrats again,
Cheers!

gunicorn automaxprocs?

In Kubernetes the available ressources could limited, and the amount of CPUs you get with traditional methods could be wrong.

For Go this gets handled with https://github.com/uber-go/automaxprocs

In your repo I see that you use gunicorn.

How do you set the gunicorn values matching to the environment?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.