How farrukhshafique87/secure-llm-serving-kubernetes works
This repository is an experimental platform for serving an LLM on Kubernetes and measuring the latency and resource overhead of security controls. The principal request path runs from a client through optional TLS ingress and API-key gateway to the FastAPI chat service, which calls Ollama. Health/readiness and Prometheus metrics are separate API capabilities. Kubernetes overlays configure RBAC, network policies, mTLS, TLS, and gateway variants; experiment results are summarized and plotted. Runtime links follow sampled code or README documentation; unsampled deployment details are not inferred.
Main entry points: app/main.py FastAPI application · ollama_client.py Ollama client · app/main.py API-key gateway · kustomization.yaml Security configurations
Components 26
LLM request path
- FastAPI application
apps/llm-api/app/main.py - Chat route
apps/llm-api/app/api/chat_routes.py - Chat schemas
apps/llm-api/app/schemas/chat_schemas.py - Chat service
apps/llm-api/app/services/chat_service.py - Ollama client
apps/llm-api/app/infrastructure/ollama_client.py - Ollama model server
kubernetes/base/deployments/ollama-deployment.yaml - Health and readiness
apps/llm-api/app/api/health_routes.py - API settings
apps/llm-api/app/core/config.py
Security controls
- Traefik TLS ingress
kubernetes/components/ingress-tls/ingress.yaml - API-key gateway
apps/llm-gateway/app/main.py - Gateway settings
apps/llm-gateway/app/config.py - Workload RBAC
kubernetes/components/rbac/kustomization.yaml - Network policies
kubernetes/components/network-policies/kustomization.yaml - Linkerd mTLS
kubernetes/components/mtls/kustomization.yaml - Security configurations
kubernetes/overlays/kind-secure/kustomization.yaml
Service telemetry
- Request middleware
apps/llm-api/app/middleware/request_id.py - Request logging
apps/llm-api/app/middleware/request_logging.py - HTTP metrics
apps/llm-api/app/middleware/metrics_middleware.py - Metric definitions
apps/llm-api/app/core/metrics_definitions.py - Prometheus
monitoring/prometheus/configmap.yaml
Experiment analysis
- k6 load generator
- Load analysis
scripts/load_table.py - Overhead analysis
scripts/overhead_table.py - Load plots
scripts/plot_load.py - Recorded results
results/exp-06-final/overhead-summary.md
Other components
- API client
Connections 26
- API client → Traefik TLS ingress: HTTPS requests
README.md - API client → API-key gateway: HTTP requests
README.md - Traefik TLS ingress → API-key gateway: forwards HTTP
README.md - API-key gateway → FastAPI application: forwards mTLS
README.md - Gateway settings → API-key gateway: configures
apps/llm-gateway/app/config.py - FastAPI application → Chat route: registers route
apps/llm-api/app/main.py - Chat route → Chat schemas: validates and returns
apps/llm-api/app/api/chat_routes.py - Chat route → Chat service: calls
apps/llm-api/app/api/chat_routes.py - Chat service → Ollama client: calls
apps/llm-api/app/services/chat_service.py - Ollama client → Ollama model server: HTTP inference
README.md - FastAPI application → Health and readiness: registers routes
apps/llm-api/app/main.py - Health and readiness → Ollama client: checks readiness
apps/llm-api/app/api/health_routes.py - Ollama client → API settings: reads settings
apps/llm-api/app/infrastructure/ollama_client.py - FastAPI application → Request middleware: installs
apps/llm-api/app/main.py - FastAPI application → Request logging: installs
apps/llm-api/app/main.py - FastAPI application → HTTP metrics: installs
apps/llm-api/app/main.py - HTTP metrics → Metric definitions: updates metrics
apps/llm-api/app/middleware/metrics_middleware.py - Chat service → Metric definitions: records tokens
apps/llm-api/app/services/chat_service.py - Prometheus → FastAPI application: scrapes metrics
- Security configurations → Workload RBAC: enables
README.md - Security configurations → Network policies: enables
README.md - Security configurations → Linkerd mTLS: enables
README.md - k6 load generator → API client: generates load
README.md - Recorded results → Load analysis: summarizes
scripts/load_table.py - Recorded results → Overhead analysis: summarizes
scripts/overhead_table.py - Load analysis → Load plots: supplies analysis
scripts/plot_load.py