Python Django web server to monitor digital ocean k8s clusters.
- About
- How to Deploy?
- How to use the app?
- Docker Hub Images
- Author Information
The web server contains user registartion and login logout system and a UI that montiors the k8s clusters from your Digital Ocean account.
I used postgresql as my Database using "postgresql_psycopg2" django DB engine.
The application can be deployed with either docker-compose or with kubernetes.
In the docker-compose there is a pgadmin service for postgres managing and debugging postgersql.
By default, the docker-compose uses the Dockerfile.test file for the django docker image.
docker installation documentation
docker-compose installation documentation
# Install docker
sudo curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo systemctl start docker && sudo systemctl enable docker
# Ensure installation succeed
sudo docker --version
# Install docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
# Ensure installation succeed
docker-compose --version
git clone https://github.com/galbirk/django-kubernetes-monitor.git
cd django-kubernetes-monitor
docker-compose up # run docker-compose up -d for background running.
app url: http://[ip/hostname]:8000
pgadmin url: http://[ip/hostname]:8080
- DJANGO_ALLOWED_HOSTS --> django Allowed Hosts variable in settings.py
- DJANGO_DEBUG --> django debug mode variable in settings.py
- DATABASE_ENGINE --> django Database Engine variable in settings.py
- DJANGO_SECRET_KEY --> django application secret key variable in settings.py
- DATABASE_NAME --> django Database name variable in settings.py
- DATABASE_USERNAME --> django Database username variable in settings.py
- DATABASE_PASSWORD --> django Database password variable in settings.py
- DATABASE_HOST --> django Database Engine variable in settings.py
- DJANGO_SUPERUSER_USERNAME --> django superuser username
- DJANGO_SUPERUSER_PASSWORD --> django superuser password
- API_KEY --> api key for Digital Ocean API
The environment variables are in .env
- POSTGRES_DB --> postgres Database name
- POSTGRES_USER --> postgres username
- POSTGRES_PASSWORD --> postgres user password
Create k8s cluster on-perm or on any cloud provider.
git clone https://github.com/galbirk/django-kubernetes-monitor.git
cd django-kubernetes-monitor/kubernetes
cd django-kubernetes-monitor/kubernetes
kubectl apply -f postgres/
NOTICE: If you want to deploy just part of the resources (deploy without persistent volume) you can access the postgres/ directory and apply each file seperatly with kubectl apply -f filename
cd django-kubernetes-monitor/kubernetes/django
# Create django-secrets
kubectl create secret generic django-secrets --from-env-file=django-secrets
cd ..
kubectl apply -f django/
# Get Load Balancer IP
kubectl get svc | grep django-svc | awk '{print $4}'
app url: http://[lb-ip/hostname]
NOTICE: Before you are deploying the app in k8s, you need to configure your app with the environmet variables below!
The environment varibles are in django-configmap.yaml and in django-secrets
- DJANGO_ALLOWED_HOSTS --> django Allowed Hosts variable in settings.py
- DJANGO_DEBUG --> django debug mode variable in settings.py
- DATABASE_ENGINE --> django Database Engine variable in settings.py
- DJANGO_SECRET_KEY --> django application secret key variable in settings.py
- DATABASE_NAME --> django Database name variable in settings.py
- DATABASE_USERNAME --> django Database username variable in settings.py
- DATABASE_PASSWORD --> django Database password variable in settings.py
- DATABASE_HOST --> django Database Engine variable in settings.py
- DJANGO_SUPERUSER_USERNAME --> django superuser username
- DJANGO_SUPERUSER_PASSWORD --> django superuser password
- API_KEY --> api key for Digital Ocean API
The environment variables are in postgres-configmap.yaml
- POSTGRES_DB --> postgres Database name
- POSTGRES_USER --> postgres username
- POSTGRES_PASSWORD --> postgres user password
- django-configmap.yaml --> configmap for django environment variables
- django-job.yaml --> job to migrate django models to database
- django-secrets --> secrets for django environment variables
- django-deployment.yaml --> deployment for django
- django-service.yml --> service for django (LB service for cloud cluster, you can uncomment the ClusterIP service and add ingress to it )
- postgres-configmap.yaml --> configmap for postgres environment variables
- postgres-deployment.yaml --> deployment for postgres
- postgres-service.yaml --> ClusterIP service for postgres
The app has registeration and login/logout systems, there are 3 roles:
- superuser --> the admins of the website, can reach to the administartion page with , http://[ip/hostname]:8000/admin. They can see all the clusters.
- partner --> they can see all the clusters that tagged with partner: tag.
- client --> they can see all the clusters that tagged with client: tag.
To let the app monitor your clusters, for many users with different roles you will have to tag the clusters.
client role tag:
client:<client_username>
partnet role tag:
partner:<partner_username>
Gal Birkman, DevOps Engineer.
email: galbirkman@gmail.com
GitHub: https://github.com/galbirk