Coder Social home page Coder Social logo

django-k8s's Introduction

Dependencies

Kubernetes Minikube Python Docker

Django & Kubernetes & Minikube

Simple project to learn how to use kubernetes and minikube in a django project.

First create a env file inside web folder, I named mine with .env, following this format

ENV_ALLOWED_HOST=localhost
DEBUG=1
DJANGO_SUPERUSER_USERNAME=admin
DJANGO_SUPERUSER_PASSWORD=mydjangopw
[email protected]
DJANGO_SECRET_KEY=raBTOqUfRTTNVj52ia9ZRQsb-KFtukcM8oz0rXbeX-k

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

REDIS_HOST=redis_db
REDIS_PORT=6380

Make sure that your variables of POSTGRES and REDIS matches with the ones defined in docker-compose.yaml. For run the databases simply run this command.

docker compose up -d

Pushing the docker image to docker hub

In order to push the docker image to the docker hub, first it's necessary to build the Dockerfile, with a name and a tag.

docker build . -t {username}/{app_name}:{tag} -f Dockerfile

Run this command in the same directory as the Dockerfile.

Afterwards, it's possible to run this command.

docker push andreapp/django_k8s --all-tags

Running Minikube and kubernetes.

Firstly it's necessary to have the docker hub running, and then start the minikube.

minikube start

It's important to let the kubernetes know your variables in the environment file, with this command.

kubectl create secret generic {name-of-env} --from-env-file=web/.env

It's possible to verify the secret with the YAML format with this command.

kubectl get secret django-k8s-web-prod-env -o YAML

And in order to run the django service, it's only necessary to run the following command.

kubectl apply -f .\k8s\apps\django-k8s-web.yaml

If there's a necessity to enter inside the kubernetes machine , it's possible running the following command.

kubectl exec -it django-k8s-web-deployment-6d6ffd4b7-9xtll -- /bin/bash

And to be able to access the service, it's necessary to run this following command.

minikube service --all # For all services
minikube service {service_name}

To get to know the service name, it's possible by running the following command.

minikube get services

If there's no necessity of running the minikube anymore, it's possible to stop the minikube service just by running the following command.

minikube delete

django-k8s's People

Contributors

andreappolarifilho avatar

Watchers

 avatar

Forkers

anishmenon

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.