galbirk / django-kubernetes-monitor

Python Django web server to monitor digital ocean k8s clusters.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

django-kubernetes-monitor

python-version Build Status
Python Django web server to monitor digital ocean k8s clusters.

k8s

Table of Contents

About

Frontend - Django Webserver

The web server contains user registartion and login logout system and a UI that montiors the k8s clusters from your Digital Ocean account.

Backend - Postgresql Database

I used postgresql as my Database using "postgresql_psycopg2" django DB engine.

Deployments options

The application can be deployed with either docker-compose or with kubernetes.

How to Deploy?

Deploy With docker-compose

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.

Install docker and docker-compose

docker installation documentation
docker-compose installation documentation

install docker and docker-compose on linux
# 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
Clone git repository and deploy the compose file
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

Environment Variables for django service
  • 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
Environment Variables for postgres service

The environment variables are in .env

  • POSTGRES_DB --> postgres Database name
  • POSTGRES_USER --> postgres username
  • POSTGRES_PASSWORD --> postgres user password

Deploy With Kubernetes

Create k8s cluster on-perm or on any cloud provider.

Clone git repository

git clone https://github.com/galbirk/django-kubernetes-monitor.git
cd django-kubernetes-monitor/kubernetes

Deploy postgres

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

Deploy django

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!

Environment Variables for django

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

Environment Variables for postgres

The environment variables are in postgres-configmap.yaml

  • POSTGRES_DB --> postgres Database name
  • POSTGRES_USER --> postgres username
  • POSTGRES_PASSWORD --> postgres user password

Kubernetes Resources

Django
  • 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
  • postgres-configmap.yaml --> configmap for postgres environment variables
  • postgres-deployment.yaml --> deployment for postgres
  • postgres-service.yaml --> ClusterIP service for postgres

How to use the app?

Users and Roles

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.

Tags

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>

Docker Hub Images

The images are published in Docker Hub:

Author Information

Gal Birkman, DevOps Engineer.
email: galbirkman@gmail.com
GitHub: https://github.com/galbirk

About

Python Django web server to monitor digital ocean k8s clusters.


Languages

Language:Python 46.4%Language:CSS 24.2%Language:HTML 24.1%Language:Shell 3.5%Language:Dockerfile 1.8%