A FastAPI-based backend service for the KubeFlare Kubernetes log viewer application.
- List Kubernetes namespaces, pods, and containers
- Fetch container logs
- Real-time log streaming via WebSocket
- CORS support for frontend integration
- Automatic Kubernetes configuration detection (in-cluster or local)
- Python 3.8 or higher
- Access to a Kubernetes cluster (local or remote)
kubectlconfigured with proper cluster access
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Linux/MacOS- Create and activate virtual environment:
python3 -m venv venv
source venv/bin/activate # On Linux/MacOS- Install required packages:
pip install fastapi kubernetes uvicorn websockets- Create requirements.txt:
pip freeze > requirements.txtAlternatively, install from requirements.txt:
pip install -r requirements.txtThe application automatically detects and loads Kubernetes configuration:
- In-cluster configuration when running inside Kubernetes
- Local configuration (
~/.kube/config) when running locally
GET /api/namespaces- List all available namespacesGET /api/pods?namespace={namespace}- List all pods in a namespaceGET /api/containers?namespace={namespace}&pod={pod}- List containers in a podGET /api/logs?namespace={namespace}&pod={pod}&container={container}&tail={tail}- Fetch container logsWebSocket /api/logs/stream- Stream real-time logs
Start the FastAPI server:
uvicorn app:app --reload --host 0.0.0.0 --port 8000The API will be available at http://localhost:8000
- The application uses FastAPI's automatic API documentation
- Access the API docs at
http://localhost:8000/docs - Access the alternative API docs at
http://localhost:8000/redoc
- The current CORS configuration allows all origins (
*) - For production, configure specific allowed origins in the CORS middleware
- Ensure proper Kubernetes RBAC permissions are set up
This project is licensed under the MIT License.