Skip to content

About

Deployment of fast api with kind cluster and cicd by jenkins

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Microservices on Kind — CI/CD with Jenkins, SonarQube, Trivy & Helm

An end-to-end local DevOps pipeline that builds, scans, and deploys two FastAPI microservices to a kind (Kubernetes-in-Docker) cluster, driven entirely by Jenkins. The pipeline runs static code analysis with SonarQube, image vulnerability scanning with Trivy, and deploys via versioned Helm charts across nonprod and prod namespaces — with a manual approval gate before production release.

Architecture

                ┌─────────────┐
   git push --> │   Jenkins   │
                └──────┬──────┘
                       │
        ┌──────────────┼───────────────┐
        ▼              ▼               ▼
   Build Images   SonarQube Scan   Trivy Image Scan
  (users/orders)   + Quality Gate   (HIGH/CRITICAL)
        │              │               │
        └──────────────┴───────────────┘
                       │
              kind load docker-image
                       │
                       ▼
            Helm upgrade --install
                       │
         ┌─────────────┴─────────────┐
         ▼                           ▼
   nonprod namespace          prod namespace
   (auto-deploy)          (manual approval gate)

Two independent FastAPI services are deployed using the same generic Helm chart, parameterized per service and per environment via separate values-*.yaml files.

Repository Structure

.
├── app1/                          # Users microservice (FastAPI)
│   ├── main.py
│   ├── Dockerfile
│   └── requirements.txt
├── app2/                          # Orders microservice (FastAPI)
│   ├── main.py
│   ├── Dockerfile
│   └── requirements.txt
├── helm/
│   ├── fastapi-app/               # Generic, reusable Helm chart
│   │   ├── Chart.yaml
│   │   ├── values.yaml
│   │   └── templates/
│   │       ├── deployment.yaml
│   │       ├── service.yaml
│   │       ├── ingress.yaml
│   │       └── _helpers.tpl
│   ├── values-users.yaml          # Per-service base values
│   ├── values-users-nonprod.yaml
│   ├── values-users-prod.yaml
│   ├── values-orders.yaml
│   ├── values-orders-nonprod.yaml
│   └── values-orders-prod.yaml
├── kind-config.yaml                # kind cluster config (ingress-ready, ports 80/443 mapped)
├── pipeline script of non prod.txt # Jenkinsfile: build → scan → deploy to nonprod
├── prod namespace/
│   └── pipeline  jenkins script.txt # Jenkinsfile: build → manual approval → deploy to prod
├── sonar-report-*.html / sonar-metrics-*.json   # Archived SonarQube reports per build
├── trivy-*-service-*.json / .txt                # Archived Trivy scan reports per build
├── non prod/, prod namespace/      # Deployment logs & resource dumps (proof of successful runs)
├── kind cluster installation proof/
├── sonarqube installation and implementation/
└── helm installation/

Services

Service Path Port Key Endpoints
users-service app1/ 8000 /, /healthz, /readyz, /users
orders-service app2/ 8000 /, /healthz, /readyz, /orders

Both are minimal FastAPI apps (fastapi==0.115.0, uvicorn[standard]==0.30.6) built on python:3.12-slim, running as a non-root appuser, and expose /healthz and /readyz for Kubernetes liveness/readiness probes.

CI/CD Pipeline

Non-Prod Pipeline (pipeline script of non prod.txt)

  1. Build Images — Docker builds users-service and orders-service, tagged with the Jenkins BUILD_NUMBER.
  2. SonarQube Analysis — Runs sonar-scanner-cli against both service source directories.
  3. Quality Gate — Pipeline aborts if SonarQube's quality gate fails.
  4. Generate SonarQube Report — Produces an HTML report and a JSON metrics snapshot (bugs, vulnerabilities, code smells, coverage, duplication, LOC) per build.
  5. Trivy Scan — Scans both images for HIGH/CRITICAL vulnerabilities, archiving JSON and table-format reports.
  6. Load Images into Kind — kind load docker-image pushes the built images directly into the local cluster (no external registry needed).
  7. Deploy to nonprod — helm upgrade --install for both services using their nonprod values files.
  8. Verify — Confirms pods, services, and ingress are healthy in the nonprod namespace.

Prod Pipeline (prod namespace/pipeline jenkins script.txt)

  1. Build Images
  2. Load Images into Kind
  3. Manual Approval Gate — input step pauses the pipeline, requiring explicit confirmation before deploying to production.
  4. Deploy to prod — helm upgrade --install for both services using their prod values files.
  5. Verify — Confirms pods, services, and ingress in the prod namespace.

Helm Chart Design

A single generic chart (helm/fastapi-app) is reused for both services and both environments. Per-service, per-environment behavior is controlled entirely through values files:

  • image.repository / image.tag — which image to deploy
  • ingress.host — e.g. users-nonprod.local, orders-prod.local
  • replicaCount, resources — scaling and limits
  • livenessProbe / readinessProbe — wired to /healthz and /readyz

Example deploy command used in the pipeline:

helm upgrade --install users-service ./helm/fastapi-app \
  -f ./helm/values-users-nonprod.yaml \
  --set image.tag=${IMAGE_TAG} \
  --namespace nonprod --create-namespace \
  --wait --timeout 180s

Local Cluster Setup

The kind-config.yaml provisions a single control-plane node labeled ingress-ready=true, with host ports 80 and 443 mapped in — ready for an NGINX ingress controller.

kind create cluster --config kind-config.yaml --name devops-demo

Tech Stack

  • App: Python, FastAPI, Uvicorn
  • Containerization: Docker
  • Orchestration: Kubernetes (kind), Helm
  • CI/CD: Jenkins (declarative pipeline)
  • Code Quality: SonarQube (quality gate enforced)
  • Security Scanning: Trivy (image vulnerability scanning)
  • Ingress: NGINX Ingress Controller

Notes

This repository includes archived pipeline run artifacts (build logs, SonarQube reports, Trivy scan outputs, kubectl get all dumps) as evidence of successful end-to-end pipeline execution across both nonprod and prod namespaces.

About

Deployment of fast api with kind cluster and cicd by jenkins

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages