The URL Shortener is a scalable, containerized service that allows users to shorten long URLs and seamlessly redirect to the original ones. Built using Flask and Redis, and deployed via Docker and Kubernetes, the project is designed for horizontal scalability and high availability. Features like Ingress routing, Horizontal Pod Autoscaling, and Redis-based persistence make it production-ready and cloud-native.
The system is composed of microservices orchestrated through Kubernetes:
- Flask App: Handles API requests to shorten and expand URLs.
- Redis: Stores mappings between short and long URLs.
- Docker: Used to containerize the application.
- Kubernetes: Handles deployment, scaling, and networking.
- Ingress Controller: Exposes the application via a custom domain.
- HPA (Horizontal Pod Autoscaler): Scales application pods automatically based on resource usage.
- 🔗 Generate and manage short URLs.
- 📦 Fully containerized with Docker.
- ☁️ Deployed using Kubernetes for easy scalability.
- ⚖️ Load balanced using Kubernetes Ingress.
- 🔁 Automatically scaled using HPA and Metrics Server.
- 🔐 Secrets and ConfigMaps for secure and configurable deployments.
Build the image locally:
docker build -t url-shortener:latest .Login to Docker Hub and push your image:
docker login
docker tag url-shortener:latest shivadarshan/url-shortener:latest
docker push shivadarshan/url-shortener:latestApply all the Kubernetes manifests:
kubectl apply -f redis-deployment.yaml
kubectl apply -f redis-service.yaml
kubectl apply -f url-shortener-deployment.yaml
kubectl apply -f url-shortener-service.yaml
kubectl apply -f configmap.yaml
kubectl apply -f redis-secret.yamlCheck if Redis pods are running:
kubectl get pods -l app=redisEnter the Redis container:
kubectl exec -it <redis-pod-name> -- shAccess Redis CLI:
redis-cli -n 0
AUTH PESU123#Replace
PESU123#with your actual Redis password from the Kubernetes secret.
minikube addons enable metrics-serverkubectl autoscale deployment url-shortener \
--cpu-percent=50 \
--min=3 \
--max=7Check the autoscaler:
kubectl get hpaminikube addons enable ingressApply your Ingress resource:
kubectl apply -f url-shortener-ingress.yamlGet your Minikube IP:
minikube ipEdit your /etc/hosts file:
sudo nano /etc/hostsAdd the following line:
<minikube-ip> url-shortener.local
Now your website will be available at:
http://url-shortener.localUse the included script stress_test_shortener.py to simulate multiple users generating short URLs concurrently.
Install Python dependencies:
pip install requests beautifulsoup4python stress_test_shortener.pyThis will:
- Simulate 200 users
- Each sending 100 requests
- Randomly generating long URLs
- Printing responses (shortened URLs or errors)
Make sure the app is accessible at
http://url-shortener.localand Ingress is working before running the script.
Base64 encode your Redis password:
echo -n "password" | base64Paste the encoded string into redis-secret.yaml.
List all pods:
kubectl get podsCheck logs of a specific pod:
kubectl logs <pod-name>List services:
kubectl get svcView deployments:
kubectl get deploymentsDescribe a specific pod:
kubectl describe pod <pod-name>Delete a Kubernetes resource:
kubectl delete -f <filename>.yamlThis project is licensed under the MIT License.
For suggestions or issues, feel free to open an issue on GitHub:
Thank you for checking out the URL Shortener project! 🎉