k3s Health Dashboard

A Streamlit dashboard for monitoring a k3s (or any Kubernetes) cluster — nodes, pods, deployments, and metrics in one place.

Architecture

app/
  main.py          FastAPI backend (REST API)
  cache.py         Streamlit cache wrappers (TTL-based)
  k8s_client.py    Kubernetes API client & data helpers
  config.py        Config loaded from environment variables
  routers/         FastAPI route handlers
app.py             Streamlit frontend entry point
k3s-dashboard.yaml Kubernetes deployment manifest

Prerequisites

  • Python 3.10+
  • A running Kubernetes cluster with a valid kubeconfig at ~/.kube/config
  • (Optional) metrics-server installed on the cluster for CPU/memory usage

Local setup

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Copy the example environment file and edit as needed:

cp .env .env.local

Key environment variables:

Variable Default Description
KUBECONFIG ~/.kube/config Path to kubeconfig
IN_CLUSTER (unset) Set to true when running as a pod
CACHE_TTL 15 Seconds between Kubernetes API calls
METRICS_ENABLED true Set false if metrics-server absent

Running locally

Streamlit dashboard:

streamlit run app.py

Opens at http://localhost:8501.

FastAPI backend only:

uvicorn app.main:app --reload

API docs at http://localhost:8000/docs.

Running tests

pytest

Deploying to Kubernetes

  1. Build and push the Docker image:
docker build -t your-registry/k3s-dashboard:latest .
docker push your-registry/k3s-dashboard:latest
  1. Update the image name in k3s-dashboard.yaml, then apply:
kubectl apply -f k3s-dashboard.yaml

The manifest creates a ServiceAccount with read-only ClusterRole access to nodes, pods, namespaces, and metrics.

S
Description
No description provided
Readme 65 KiB
Languages
Python 96%
Dockerfile 4%