A web application for calculating Exponentially Weighted Moving Averages (EWMA) and simple averages. Built with FastAPI backend and React frontend. The application is containerized with Docker and deployed on a local K8s cluster using Kind.
├── backend/ # FastAPI backend service
│ ├── app/
│ │ ├── main.py # Application entry point
│ │ ├── routers/ # API route handlers
│ │ ├── schemas.py # Pydantic models
│ │ └── services.py # Business logic
│ ├── tests/ # Backend tests
│ ├── Dockerfile # Backend container image
│ └── requirements.txt # Python dependencies
│
├── frontend/ # Frontend application (React + Vite + TS)
│ ├── src/
│ │ ├── assets/ # Static assets (images, fonts, icons, etc.)
│ │ ├── components/ # Reusable UI components
│ │ ├── api/ # API calls
│ │ ├── types/ # Shared types/interfaces
│ │ ├── App.tsx # Root component
│ │ └── main.tsx # Entry point
│ │
│ ├── public/ # Public static files
│ │ └── favicon.ico
│ │
│ ├── Dockerfile # Frontend Docker image
│ ├── index.html # Root HTML file
│ ├── package.json
│ ├── tsconfig.json
│ ├── tsconfig.app.json
│ ├── tsconfig.node.json
│ ├── vite.config.ts
│ ├── eslint.config.js
│ ├── .gitignore
│ └── README.md
│
├── k8s/ # Kubernetes configurations
│ └── ewma-calculator/ # Helm chart
│ ├── templates/ # K8s resource templates
│ ├── values.yaml # Default values
│ ├── values-staging.yaml
│ └── values-production.yaml
│
├── scripts/ # Automation scripts
│ ├── build_images.sh # Build Docker images
│ ├── push_images.sh # Push images to Docker Hub
│ ├── test_backend.sh # Run backend tests
│ ├── test_frontend.sh # Test and build frontend
│ └── deploy.sh # Deploy to Kubernetes (Kind in this case)
│
└── .github/workflows/ # CI/CD pipeline
└── main.yml # GitHub Actions workflow
- Docker
- kubectl
- Helm 3
- Kind (for local deployment)
- Python 3.12+ (for local development)
- Node.js 18+ (for local development)
cd backend
pip install -r requirements.txt
uvicorn app.main:app --reloadcd frontend
npm install
npm run devbash scripts/test_backend.shbash scripts/test_frontend.shbash scripts/build_images.shbash scripts/push_images.sh
In the root directory of this repo, there is a docker-compose.yaml file. Run the command below to locally run the application.
docker compose upFrontend accessible at localhost:5173 and backend at localhost:8000
The GitHub Actions workflow automatically:
- Runs backend tests
- Runs frontend tests and builds
- Builds Docker images with appropriate tags
- Pushes images to Docker Hub
- Push to main branch
- Manual worklow dispatch
bash scripts/deploy.shThis script will:
- Install Kind and Helm (if not present)
- Create a Kind cluster
- Deploy staging environment
- Deploy production environment
- Set up port forwarding (for local testing)
- Staging
- Frontend: http://localhost:4000
- Backend: http://localhost:9000
- Production :
- Frontend: http://localhost:3000
- Backend: http://localhost:8000
kind create cluster --config k8s/ewma-calculator/kind-config.yaml --name ewma-clustercd k8s/ewma-calculator
helm upgrade --install ewma-staging . \
--values values-staging.yaml \
--waitTo see all running resources inside the staging namespace, run the command below
kubectl get all -n staginghelm upgrade --install ewma-production . \
--values values-production.yaml \
--waitTo see all running resources inside the production namespace, run the command below
kubectl get all -n productionPort forward to access locally
- Frontend
kubectl port-forward -n staging svc/frontend-service 5173(any_port):80- Backend
kubectl port-forward -n staging svc/backend-service 8000(any_port):80The same can be followed for production, just replace staging with production
curl http://localhost:8000/healthShould return: {"status":"healthy"}
Remove the Kind cluster
kind delete cluster --name ewma-cluster🔎 Role of Metrics Server in HPA - Metrics Server provides live CPU and memory usage data from pods via the metrics.k8s.io API, which the Horizontal Pod Autoscaler (HPA) uses to scale workloads up or down.
⚠️ Important: Without Metrics Server, HPA cannot fetch CPU/memory usage.
Will use Helm to install metric server
- Add Metrics Server repo
This tells Helm where to find the metrics-server chart.
helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/
- Update Helm repos
Ensures you have the latest charts from all configured repositories.
helm repo update
- Skipping TLS verification
helm up grade --install metrics-server metrics-server/metrics-server \ -n kube-system \ --set args={--kubelet-insecure-tls}
By default metric server uses TLS to connect to Kubelets. But since we are using a local environment Kind, kubelets don't have valid certificates, so we need the above command to bypass TLS verification