This repository contains a complete project for deploying a ToDo web application (built with the Django framework) to a Kubernetes cluster using a Helm Chart.
The main objective of this project is to demonstrate a reliable and scalable deployment of a multi-component application (web server and database) using modern Infrastructure as Code (IaC) and container orchestration practices.
The project consists of the following main components:
- Web Application (Django): The backend that provides a REST API and an interactive UI (using Skeleton CSS and jQuery). The source code is located in the
src/directory. - Database (MySQL): Stores user data and their task lists.
- Helm Chart (
todoapp): The main chart for deploying the application and all required Kubernetes resources. - Helm Sub-chart (
mysql): A child chart for deploying the MySQL database (as a StatefulSet) with persistent data storage (Persistent Volumes).
All infrastructure configuration is encapsulated within the Helm Chart. Key features and settings include:
- Configuration Flexibility: All crucial parameters, such as Namespace names, resource names (generated automatically using
.Chart.Name), database connections, and secrets, are extracted and managed through thevalues.yamlfile. - Secrets and Environment Variables Management: The
rangefunction is used to dynamically generate secretsdataand conveniently map them into Environment Variables inside the Deployment. - Scaling and HPA: A Horizontal Pod Autoscaler (HPA) is configured to automatically scale pods based on resource utilization (e.g., target CPU and memory utilization is configured in
values.yaml). - Resource Allocation: Clearly defined
requestsandlimitsfor CPU and RAM to ensure stable operation within the cluster. - High Availability:
RollingUpdateparameters are configured for seamless updates.Affinity,Node Affinity, andTolerationsare set (e.g., to schedule the database on specific nodes withapp=mysqltaints and labels).
- Data Persistence: A
PersistentVolumeClaim(PVC) is used for reliable MySQL data storage with specified capacity requirements. - Security: Access to the Kubernetes API is restricted using
ServiceAccountand corresponding RBAC objects.
-
Create the cluster: For local testing, you can spin up a cluster using the provided
cluster.ymlconfiguration file:kind create cluster --config cluster.yml
-
Prepare nodes (Taints/Labels): Assign the appropriate labels and taints to the database node to ensure correct pod scheduling:
kubectl taint nodes <node-name> app=mysql:NoSchedule
-
Deploy using the automated script: For a quick start, you can use the
bootstrap.shscript, which contains all the necessary commands to deploy prerequisites and thetodoappHelm Chart to your cluster:./bootstrap.sh
If you want to run the Django application locally (outside of Kubernetes):
- Go to the source directory and install the dependencies (Python 3.8+ required):
cd src pip install -r requirements.txt - Run database migrations:
python manage.py migrate
- Start the development server:
The application will be available at: http://localhost:8000/ (API is available at
python manage.py runserver
/api/).