π Flask DevOps Pipeline β Docker | Kubernetes | CI/CD | AWS ECS | Terraform | Ansible | Monitoring
A production-style DevOps project built from scratch β a Python Flask app containerized with Docker, orchestrated with Kubernetes, deployed to AWS ECS Fargate, with static files on S3, secure access via IAM roles, infrastructure provisioned using Terraform, server configuration automated with Ansible, and live metrics tracked via Prometheus + Grafana.
Developer (git push)
β
βΌ
GitHub Actions (CI/CD Pipeline)
β
βββ Install dependencies
βββ Build Docker image
βββ Push to Docker Hub
β
ββββΊ AWS ECS Fargate (Live Deployment)
β βββ Pulls image from Docker Hub
β βββ Runs Flask container (port 5000)
β βββ Serves static files from AWS S3
β βββ IAM Role β secure S3 access
β
ββββΊ Terraform β Provisions EC2 + Security Group
β βββ Ansible β Installs Docker + Deploys container
β
ββββΊ Prometheus + Grafana β Live Monitoring Dashboard
| Layer | Technology |
|---|---|
| Application | Python 3.10, Flask |
| Containerization | Docker |
| Orchestration | Kubernetes (Minikube) |
| CI/CD | GitHub Actions |
| Container Registry | Docker Hub |
| Cloud Deployment | AWS ECS Fargate |
| Static Files | AWS S3 |
| Access Control | AWS IAM Roles |
| Infrastructure as Code | Terraform |
| Configuration Management | Ansible |
| Monitoring | Prometheus + Grafana |
- β Flask app containerized with Docker
- β Kubernetes deployment with 2 replicas (local)
- β Automated CI/CD β every push triggers build & push to Docker Hub
- β Live deployment on AWS ECS Fargate
- β Static assets served from AWS S3
- β IAM role attached to ECS task for secure S3 access
- β EC2 + Security Group provisioned via Terraform (IaC)
- β Ansible playbook automates Docker install and container deployment
- β Prometheus + Grafana monitoring with live dashboards
βββ app/
β βββ app.py # Flask application with Prometheus metrics
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Docker image definition
βββ k8s/
β βββ deployment.yaml # Kubernetes deployment (2 replicas)
β βββ service.yaml # Kubernetes NodePort service
βββ terraform/
β βββ main.tf # EC2 + Security Group resources
β βββ variables.tf # Input variables
β βββ outputs.tf # Output values (public IP)
βββ ansible/
β βββ inventory.ini # Target hosts
β βββ playbook.yml # Automate Docker + container deployment
βββ monitoring/
β βββ prometheus.yml # Prometheus scrape config
βββ docker-compose.yml # Flask + Prometheus + Grafana stack
βββ .github/
β βββ workflows/
β βββ ci.yml # GitHub Actions CI/CD pipeline
βββ README.md
Triggered automatically on every push to main:
git push β Install deps β Build Docker image β Push to Docker Hub
Secrets required in GitHub β Settings β Actions:
| Secret | Value |
|---|---|
DOCKER_USERNAME |
Docker Hub username |
DOCKER_PASSWORD |
Docker Hub access token |
cd app
docker build -t sna-app .
docker run -p 5000:5000 sna-appVisit: http://localhost:5000
Live image: docker.io/syedmaaz001/sna-app:latest
minikube start
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
minikube service sna-service| Service | Purpose |
|---|---|
| ECS Fargate | Serverless container hosting |
| ECR | Private Docker image registry |
S3 (sna-static-files) |
Static file storage |
IAM (sna-ecs-s3-role) |
Secure S3 read access for ECS |
| Security Group | Allow inbound traffic on port 5000 |
cd terraform
terraform init
terraform plan
terraform apply
terraform destroy # cleanup when doneWhat Terraform creates:
- EC2 instance (
t3.micro) with Docker pre-installed - Security Group allowing port 5000 and SSH
- Auto-pulls Docker image and starts Flask app via
user_data
cd ansible
ansible-galaxy collection install community.docker
ansible-playbook -i inventory.ini playbook.yml --ask-become-passWhat Ansible automates:
- Installs Docker and dependencies
- Starts Docker service
- Pulls Flask image from Docker Hub
- Runs container with auto-restart policy
docker compose up --build| Service | URL |
|---|---|
| Flask App | http://localhost:5000 |
| Prometheus | http://localhost:9090 |
| Grafana | http://localhost:3000 (admin/admin) |
Metrics tracked:
flask_http_request_totalβ total requests by endpoint and statusflask_http_request_duration_secondsβ response latency
git clone https://github.com/MaazAhmed47/devops-flask-aws.git
cd devops-flask-aws
cd app
docker build -t sna-app .
docker run -p 5000:5000 sna-appSyed Maaz Ahmed β IT Student, SSUET Karachi, Pakistan



