Skip to content

This project demonstrates deploying a microservices-based FastAPI e-commerce application using modern DevOps tooling and best practices:

Notifications You must be signed in to change notification settings

madhvi-n/fastapi-ecommerce-microservice-devops

Repository files navigation

FastAPI Ecommerce Microservice DevOps Project

Docker Image CI CodeQL Advanced FastAPI CI Kubernetes

🚀 Project Overview

This project demonstrates deploying a microservices-based FastAPI e-commerce application using modern DevOps tooling and best practices:

  • Microservices: users and products services built with FastAPI.
  • Containerization: Docker for packaging apps.
  • Orchestration: Kubernetes (Minikube) for deployment and scaling.
  • Configuration Management: Helm charts for templating Kubernetes manifests.
  • Infrastructure as Code: Terraform for provisioning cloud resources.
  • Monitoring & Observability: Prometheus + Grafana for metrics; ELK Stack for logging.
  • CI/CD: Automated pipelines for build, test, and deployment.

Features

  • Microservices architecture with independent services for users, products, and more
  • Authentication with OAuth (Google, GitHub)
  • Role-based access control (Admin, Staff, Customer roles)
  • PostgreSQL or SQLite database support via SQLAlchemy ORM
  • JWT token authentication
  • Dockerized services for consistent environments
  • Kubernetes manifests for container orchestration
  • Terraform integration for cloud infrastructure (planned)

📦 Prerequisites

  • Docker
  • Minikube & kubectl
  • Helm
  • Terraform
  • Prometheus + Grafana (Optional)
  • ELK Stack (Optional)

🛠 Setup & Deployment

Initial SetUp

  1. Clone the repo:

    git clone https://github.com/madhvi-n/fastapi-ecommerce-microservice-devops.git
    cd fastapi-ecommerce-microservice-devops
  2. Environment variables Refer to services/users/.env.example for required variables like:

  • DATABASE_URL
  • JWT_SECRET_KEY
  • GOOGLE_CLIENT_ID

1. Build and load Docker images

Build service images locally:

docker build -t users-service:latest -f ./services/users/Dockerfile .
docker build -t products-service:latest -f ./services/products/Dockerfile .

Load images into Minikube’s Docker daemon:

minikube image load users-service
minikube image load products-service

2. Deploy with Kubernetes K8 deployment guide

Apply base Kubernetes manifests (deployments, services, configmaps, secrets):

kubectl apply -f k8s/base

Use Helm charts for easier management Helm deployment guide

helm install users ./helm-chart/users
helm install products ./helm-chart/products

Use ingress Ingress deployment guide

kubectl apply -f ingress.yaml

# Check if ingress is created
kubectl get ingress

# Check if ingress is running
kubectl get pods -n ingress-nginx

Now you can access your services from your browser:

http://app.local/users
http://app.local/products

3. Infrastructure Provisioning with Terraform (Locally)

Use Terraform to provision cloud infrastructure resources (e.g., AWS S3 buckets, databases, etc.):

terraform init
terraform apply

4. Monitoring & Logging

  • Prometheus + Grafana: Monitor app and cluster metrics with real-time dashboards.
  • ELK Stack: Centralized log collection and analysis across services.

🔧 Useful Commands

# Kubernetes commands
kubectl get pods
kubectl get svc
kubectl logs <pod-name>
kubectl port-forward service/nginx-service 8080:80

# Helm commands
helm install ecommerce ./helm-chart
helm upgrade ecommerce ./helm-chart
helm uninstall ecommerce

# Terraform commands
terraform init
terraform plan
terraform apply
terraform destroy

# Docker commands
docker build -t users-service:latest ./services/users
docker push <registry>/users-service:latest
docker-compose up
docker-compose build
docker-compose down

🧰 DevOps Toolkit Overview

Docker

  • Containerize microservices for consistent environments.

Kubernetes (Minikube + kubectl)

  • Orchestrate deployment, scaling, and management of containers.

Helm

  • Package and manage Kubernetes manifests as charts for templating and reusability.

Terraform

  • Infrastructure as code to provision and manage cloud resources.

Prometheus & Grafana

  • Monitor system and application metrics with dashboards and alerts.

ELK Stack (Elasticsearch, Logstash, Kibana)

  • Centralized logging and visualization for troubleshooting and auditing.

CI/CD

  • Automate build, test, and deployment for rapid and reliable delivery.

💡 Future Enhancements:

  • GitHub Actions or Jenkins for CI/CD
  • Docker Hub or GitHub Container Registry
  • Istio or Linkerd for service mesh
  • ELK stack (Elasticsearch, Logstash, Kibana) or Loki or Jaeger for logging/tracing
  • Vault or Sealed Secrets for secret management
  • Ansible, Chef, Puppet for Configuration management

📚 References

About

This project demonstrates deploying a microservices-based FastAPI e-commerce application using modern DevOps tooling and best practices:

Topics

Resources

Stars

Watchers

Forks