Skip to content

vikipranata/simple-virtmgr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-virtmgr

A minimal web app to manage KubeVirt VirtualMachines in a single namespace or across multiple namespaces.

  • Frontend: Static HTML/CSS/JS in app/static/
  • Backend: FastAPI serving REST and WebSocket proxy
  • Target namespace: from POD_NAMESPACE env

Disclaimer

This repository is provided for hobby and educational purposes only. If you plan to use it in a production environment, it will most likely require significant customization, testing, and security audits. Please fork and build your own application.

Features

  • Bearer token auth (simple): supply a token in the login modal. Backend validates against API_TOKEN.
  • List VMs in namespace (or across all namespaces in Admin Mode)
  • Start/Stop/Restart VMs
  • VNC console access
  • Serial console access
  • Admin Mode for managing VMs across multiple namespaces
  • Session timeout for security
  • Responsive web interface

Showcase

user-simple-virtmgr-login.png

user-simple-virtmgr-list-admin.png

user-simple-virtmgr-list.png

user-simple-virtmgr-console.png

API

Base: /api/v1

User Mode Endpoints

  • GET /namespace → Get current namespace
  • GET /vms/{namespace} → List VMs in specified namespace [ { name, namespace, status } ]
  • POST /vms/{namespace}/{name}/start → Start VM
  • POST /vms/{namespace}/{name}/stop → Stop VM
  • POST /vms/{namespace}/{name}/restart → Restart VM
  • POST /vms/{namespace}/{name}/console-token → Generate temporary token for console access
  • WebSocket /vms/{namespace}/{name}/console → Serial console WebSocket
  • WebSocket /vms/{namespace}/{name}/vnc → VNC console WebSocket
  • GET /health → Liveness/readiness

Admin Mode Endpoints

  • GET /namespace → Get current namespace and admin mode status
  • GET /namespaces → List all namespaces with kubevirt.io/namespace= label
  • GET /vms/{namespace} → List VMs in specified namespace [ { name, namespace, status } ]
  • POST /vms/{namespace}/{name}/start → Start VM in specified namespace
  • POST /vms/{namespace}/{name}/stop → Stop VM in specified namespace
  • POST /vms/{namespace}/{name}/restart → Restart VM in specified namespace
  • POST /vms/{namespace}/{name}/console-token → Generate temporary token for console access
  • WebSocket /vms/{namespace}/{name}/console → Serial console WebSocket
  • WebSocket /vms/{namespace}/{name}/vnc → VNC console WebSocket
  • GET /health → Liveness/readiness

Static UI available at / and served at /static/*.

Configuration

Set these environment variables:

  • ADMIN_MODE — set admin mode to access all VMs across namespaces (default false)
  • POD_NAMESPACE — target namespace (default default). Ignored in ADMIN_MODE.
  • API_TOKEN — token accepted by the API (used by UI)
  • LOG_LEVEL — logging level (default INFO, options: TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL)

The included manifests already inject POD_NAMESPACE and API_TOKEN using a ServiceAccount and Secret.

Run locally

Prereqs: Python 3.11+, access to a cluster (via kubeconfig), and KubeVirt installed.

# from repo root
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
export POD_NAMESPACE=default
export API_TOKEN=devtoken123
# Optional: set logging level (default is INFO)
# export LOG_LEVEL=DEBUG
# use your cluster kubeconfig
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload

Open http://localhost:8000, enter your API token, manage VMs.

Build image

# optional: set image tag
IMAGE=${IMAGE:-simple-virtmgr:dev}
docker build -t "$IMAGE" .

Kubernetes deploy

User Mode Deployment

# Create namespace
kubectl create namespace simple-virtmgr

# Create secret with your desired API token
kubectl apply -f manifests/simple-virtmgr-user/secret.yaml
# RBAC, Service, Deployment
kubectl apply -f manifests/simple-virtmgr-user/rbac.yaml
kubectl apply -f manifests/simple-virtmgr-user/service.yaml
kubectl apply -f manifests/simple-virtmgr-user/deployment.yaml

Admin Mode Deployment

# Create namespace
kubectl apply -f manifests/simple-virtmgr-admin/namespace.yaml

# Create secret with your desired API token
kubectl apply -f manifests/simple-virtmgr-admin/secret.yaml
# RBAC, Service, Deployment
kubectl apply -f manifests/simple-virtmgr-admin/rbac.yaml
kubectl apply -f manifests/simple-virtmgr-admin/service.yaml
kubectl apply -f manifests/simple-virtmgr-admin/deployment.yaml

Update the image: field in the deployment YAML files if you built a custom image.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Credit to

About

A simple web dashboard for managing KubeVirt Virtual Machines

Topics

Resources

License

Stars

Watchers

Forks