This repository contains an LLM (Large Language Model) inference system deployed in Kubernetes using FastAPI, Kafka, and Open WebUI. The system is designed to distribute prompt requests across multiple LLM pods efficiently. It uses Kafka as a message broker for decoupling the request-response cycle and can optionally support KubeRay for distributing single prompts across multiple LLM pods.
- Users interact with Open WebUI (or Gradio WebUI, if used).
- They input a prompt which is then submitted to FastAPI.
- Acts as an API Gateway.
- Receives prompt requests from WebUI.
- Produces prompt requests into the Kafka topic
prompt-requests. - Randomly selects one LLM Pod to send the request.
- Optionally, with KubeRay, a single prompt can be distributed across multiple LLM pods.
- Once the response is available, it consumes messages from the Kafka topic
inference-resultsand forwards them back to WebUI.
- Manages the distribution of prompt-requests to available LLM Pods.
- Stores generated responses in the inference-results topic.
- Each LLM Pod runs an instance of Ollama.
- Listens for Kafka messages on
prompt-requests. - Generates responses and sends them to
inference-results.
- Allows single prompt to be split across multiple LLM pods for parallel inference.
- Useful for large models and resource-heavy inference tasks.
- Once the LLM inference is complete, the response is published to Kafka (
inference-results). - FastAPI consumes the result and sends it back to WebUI.
- WebUI displays the response to the user.
Ensure Kafka and Zookeeper are running in Kubernetes.
kubectl create namespace kafka
kubectl apply -f kafka-deployment.yamlApply the Ollama deployment and service:
kubectl create namespace llm
kubectl apply -f ollama-deployment.yaml
kubectl apply -f ollama-service.yamlkubectl apply -f fastapi-deployment.yaml
kubectl apply -f fastapi-service.yamlkubectl create namespace open-webui
kubectl apply -f open-webui-deployment.yaml
kubectl apply -f open-webui-service.yamlFind the node's public IP and access Open WebUI at:
http://<PUBLIC_NODE_IP>:30081
Modify the OLLAMA_BASE_URL to:
env:
- name: OLLAMA_BASE_URL
value: "http://ollama-service.llm.svc.cluster.local"If KubeRay is installed, you can enable distributed inference across multiple LLM pods:
kubectl apply -f kuberay-deployment.yamlThis will distribute a single prompt across multiple pods for faster inference.
This setup enhances an LLM inference system using FastAPI, Kafka, Open WebUI, and multiple LLM pods. We incorporate performance monitoring and scalability features using Redis, Grafana, Locust, LitmusChaos, and KubeRay.
| Feature | Tool Used | Outcome |
|---|---|---|
| FastAPI Caching | Redis Sidecar | Reduces redundant LLM calls |
| Redis Monitoring | Redis Exporter + Grafana | Tracks cache hit/miss ratio |
| Load Testing | Locust | Ensures FastAPI scalability |
| Chaos Testing | LitmusChaos | Ensures resilience |
| Dynamic Scaling | KubeRay | Distributes LLM loads |
- FastAPI Caching → Reduces redundant requests using Redis.
- Redis Monitoring → Tracks cache hit/miss ratio using Grafana dashboards.
- Load Testing → Locust simulates concurrent users & measures FastAPI performance.
- Chaos Testing → LitmusChaos injects failures to test system resilience.
- Dynamic Scaling → KubeRay distributes LLM requests across multiple pods.
kubectl get pods -n llmkubectl exec -it kafka-<pod-name> -n kafka -- kafka-topics.sh --list --bootstrap-server kafka.kafka.svc.cluster.local:9092kubectl logs -f open-webui-deployment-<pod-name> -n open-webuiThis LLM inference system provides a scalable, distributed, and efficient way to handle AI inference workloads using FastAPI, Kafka, Open WebUI, and KubeRay.
