This project is a Flask-based microservices application designed to display CTF (Capture the Flag) scoreboards. It uses Docker and Kubernetes for deployment, ensuring scalability, ease of management, and portability.
- CTF Scoreboard System
F:\WAYBACK-CTFD
│ docker-compose.yml # Docker Compose file to orchestrate multiple containers (Flask app and database) for local development
│ echo.txt # Example text file (purpose may vary)
│ README.md # Project documentation with setup, usage, and deployment instructions
│
├───app # Main application folder containing Flask code and configuration
│ │ app.py # Main Flask application file with route definitions and logic
│ │ Dockerfile # Dockerfile to build the Flask application container image
│ │ requirements.txt # List of Python dependencies required for the Flask app
│ │
│ ├───instance # Flask instance folder to store runtime files and database (if SQLite is used)
│ │ database.db # SQLite database file (if using SQLite for development)
│ │
│ ├───static # Folder for static assets (CSS, JavaScript, images, etc.)
│ │
│ └───templates # HTML templates for rendering pages in Flask
│ all_scoreboards.html # Template to display all available scoreboards
│ base.html # Base template for consistent layout and styling across pages
│ index.html # Homepage template for the CTF Scoreboard System
│ scoreboard.html # Template to display individual scoreboard details
│
└───k8s # Kubernetes configuration folder for deploying microservices
db-deployment.yaml # Deployment configuration for the database service
db-service.yaml # Service configuration for database (ClusterIP or internal access only)
flask_app-deployment.yaml # Deployment configuration for the Flask application
flask_app-hpa.yaml # Horizontal Pod Autoscaler to auto-scale Flask pods based on CPU usage
flask_app-service.yaml # LoadBalancer service to expose Flask app externally
- Python 3.9+: To run the application locally without Docker.
- Docker: To containerize the application.
- Docker Compose: For local multi-container setup.
- Kubernetes: For orchestrating and deploying microservices.
- kubectl: CLI tool to manage Kubernetes clusters.
-
Clone the repository:
git clone https://github.com/sondt1337/wayback-ctf.git cd wayback-ctf
-
Install Python dependencies: If you are running locally without Docker, install the dependencies manually:
pip install -r app/requirements.txt
To run the application without Docker, follow these steps:
-
Navigate to the
app
directory:cd app
-
Set environment variables for Flask:
-
On Linux/macOS:
export FLASK_APP=app.py export FLASK_ENV=development
-
On Windows (Command Prompt):
set FLASK_APP=app.py set FLASK_ENV=development
-
On Windows (PowerShell):
$env:FLASK_APP = "app.py" $env:FLASK_ENV = "development"
-
-
Run the Flask application:
python app.py
The application will be accessible at
http://127.0.0.1:5000
.
To run the application locally with Docker Compose:
docker-compose up --build
This will start both the Flask app and the SQLite database in Docker containers, exposing the Flask app on port 5000
.
The Dockerfile
in app/
sets up the Flask environment:
# Use Python 3.9
FROM python:3.9-slim
# Install necessary packages
RUN apt-get update && apt-get install -y build-essential && rm -rf /var/lib/apt/lists/*
# Set up the working directory
WORKDIR /app
# Copy application files into the container
COPY . /app
# Install required libraries
RUN pip install --no-cache-dir -r requirements.txt
# Run Flask startup command
CMD ["python", "app.py"]
This project includes Kubernetes configurations to deploy the application with microservices architecture. Each component (Flask app and database) is deployed as a separate service.
To deploy the services to a Kubernetes cluster, run the following:
kubectl apply -f k8s/
This command will deploy:
flask-app
: The Flask application with a LoadBalancer service for external access.sqlite-db
: SQLite database as a ClusterIP service, accessible only within the cluster.flask-app-hpa
: A Horizontal Pod Autoscaler to scale the Flask application based on CPU utilization.
- flask_app-deployment.yaml: Defines the Flask app deployment with replicas.
- flask_app-service.yaml: Exposes the Flask app with a LoadBalancer.
- db-deployment.yaml: Defines the SQLite database deployment.
- db-service.yaml: Exposes the database as an internal ClusterIP service.
- flask_app-hpa.yaml: Configures auto-scaling for the Flask app.
-
Check Service Status:
kubectl get services
Note the external IP of the
flask-app-service
LoadBalancer. -
Open the Application: Visit the external IP in your browser:
http://<EXTERNAL-IP>:80
To view logs of the Flask application, use:
kubectl logs -f <flask-app-pod-name>
The Horizontal Pod Autoscaler (HPA) automatically scales the Flask application based on CPU utilization. You can check the HPA status with:
kubectl get hpa
You can manually scale the number of replicas with:
kubectl scale deployment flask-app --replicas=5
-
Database Connection Issues: Ensure the database service (
sqlite-db
) is running correctly and accessible by checking the pod and service status. -
Application Access: If the LoadBalancer IP is not accessible, confirm that your Kubernetes cluster supports LoadBalancer services, or use
kubectl port-forward
to access the service locally.
This project is licensed under the BSD 3-Clause License.
This README.md
should give clear instructions for setting up, running, and scaling the application using Docker and Kubernetes.