This project is a microservice-based URL shortener application deployed using Docker and Kubernetes. The project contains multiple components, including a Python application, Helm charts for managing Kubernetes resources, and Docker configuration files.
-
app/: Contains the main application code.
- app.py: The main Python script for the application.
- templates/: HTML templates for rendering web pages.
-
Chart/: Helm chart configuration for deploying the application on Kubernetes.
- Chart.yaml: Metadata about the Helm chart, including the name, version, and description.
- values.yaml: Default values for the Helm chart that can be customized during deployment.
-
docker-compose.yml: Configuration file for Docker Compose to manage multi-container Docker applications.
-
Dockerfile: Defines the environment and instructions for building the Docker image for the application.
-
kubernetes/: Kubernetes YAML configurations for deploying the application.
- app-dep.yml: Deployment file for the application.
- configmap.yml: Configuration file to store non-sensitive application settings.
- db-dep.yml: Deployment file for the database.
- db-statefulset.yml: StatefulSet configuration for ensuring the database runs in a stable and consistent environment.
- hpa-dep.yml: Configuration for the Horizontal Pod Autoscaler.
- secret.yml: Configuration for managing sensitive data such as passwords.
- volume.yml: Configuration file for managing persistent volumes.
-
README.md: This documentation file.
-
requirements.txt: Lists the dependencies for the Python application.
-
Clone the repository:
git clone https://github.com/mirzaim/url-shortner.git cd url-shortner
-
Install Python dependencies:
pip install -r requirements.txt
-
Build the Docker image:
docker build -t url-shortner-image .
-
Deploy the application using Docker Compose:
docker-compose up
-
Create the ConfigMap, Secrets, and Persistent Volume:
kubectl apply -f kubernetes/configmap.yml kubectl apply -f kubernetes/secret.yml kubectl apply -f kubernetes/volume.yml
-
Deploy the database and application:
kubectl apply -f kubernetes/db-dep.yml kubectl apply -f kubernetes/app-dep.yml
-
(Optional) Apply Horizontal Pod Autoscaler:
kubectl apply -f kubernetes/hpa-dep.yml
Once the application is deployed, you can use the /shortit
endpoint to shorten URLs. Here's an example using curl
to test the API:
-
Shorten a URL:
curl -X POST http://<your-server-ip>:<your-port>/shortit -H "Content-Type: application/json" -d '{"path_to": "https://www.example.com"}'
Replace
<your-server-ip>
and<your-port>
with the actual IP and port of your deployed application. -
Visit the shortened URL:
The response will contain a shortened URL. You can visit this URL, and the system will redirect you to the original URL.