Intelligent NRP + Kubernetes routing and management system
A smart routing system that analyzes user intent and routes requests to appropriate handlers:
- Command Detection: Routes kubectl/k8s operational commands to k8s_operations.py
- Question/Explanation: Routes documentation questions to NRP+K8s hybrid system
- π€ Intelligent Intent Classification: Uses NRP LLM to determine if user wants to execute commands or get explanations
- β‘ Complete K8s Operations: Create, delete, list, describe pods and deployments through Python Kubernetes client
- π Resource Creation: Create pods and deployments with configurable parameters (image, replicas, resources)
- π NRP Documentation Integration: Get comprehensive guidance using NRP LLM with contextual examples
- π Smart Fallback: Handles unclear intents and vague descriptions with intelligent defaults
- π¬ Interactive Mode: Chat interface for continuous interaction
- π§© Modular Architecture: Clean package structure for easy maintenance and extension
# Clone or copy the nrp_k8s_system directory
cd nrp_k8s_system
# Install dependencies
pip install -r requirements.txt
# Or install as a package
pip install -e .-
Copy the environment template:
cp config/default.env .env
-
Edit
.envwith your NRP credentials:NRP_API_KEY=your_nrp_api_key_here NRP_BASE_URL=https://llm.nrp-nautilus.io/ NRP_MODEL=gemma3
-
Ensure kubectl is configured for your NRP cluster
Single command mode:
# List and inspect resources
python -m nrp_k8s_system.intelligent_router "list my pods"
python -m nrp_k8s_system.intelligent_router "describe pod myapp"
python -m nrp_k8s_system.intelligent_router "logs my-pod"
# Create resources
python -m nrp_k8s_system.intelligent_router "create pod my-app image=nginx"
python -m nrp_k8s_system.intelligent_router "create deployment web-app image=nginx replicas=3"
# Delete resources
python -m nrp_k8s_system.intelligent_router "delete pod my-app"
python -m nrp_k8s_system.intelligent_router "delete deployment web-app"
# Documentation/guidance
python -m nrp_k8s_system.intelligent_router "How do I request GPUs?"
python -m nrp_k8s_system.intelligent_router "What are storage best practices?"Interactive mode:
python -m nrp_k8s_system.intelligent_routerUsing as installed package:
# If installed with pip install -e .
nrp-k8s "list pods"
intelligent-routernrp_k8s_system/
βββ __init__.py # Package initialization
βββ intelligent_router.py # Main routing logic
βββ cli.py # CLI entry point
βββ requirements.txt # Dependencies
βββ pyproject.toml # Package configuration
βββ core/ # Core utilities
β βββ __init__.py
β βββ nrp_init.py # NRP LLM initialization
βββ systems/ # System components
β βββ __init__.py
β βββ k8s_operations.py # Kubernetes operations
β βββ qain.py # Information extraction (optional)
βββ cache/ # Cache directory
β βββ .gitkeep
βββ config/ # Configuration templates
βββ default.env # Environment template
- Uses NRP LLM to analyze user input
- Classifies as COMMAND, EXPLANATION, or UNCLEAR
- Fallback to keyword-based classification if LLM fails
- Routes kubectl operations to
k8s_operations.py - Full CRUD Operations: Create, read, update, delete for pods and deployments
- List & Inspect: list, get, describe for pods, services, deployments, jobs, etc.
- Utility Functions: logs, exec commands for debugging
- Works in 'gsoc' namespace by default
- Provides comprehensive NRP+K8s guidance
- Generates contextual examples based on user questions
- Covers GPU requests, storage setup, job scheduling, etc.
Listing & Inspection:
"list my pods" β Shows pods in gsoc namespace
"get services" β Lists services
"describe pod myapp" β Pod details
"show deployments" β Deployment list
"list nodes" β Cluster nodes
"logs my-pod" β Pod logsResource Creation:
"create pod my-app" β Creates basic pod
"create pod nginx-pod image=nginx" β Creates nginx pod
"create deployment web-app" β Creates basic deployment
"create deployment api replicas=3" β Creates deployment with 3 replicas
"deploy nginx image=nginx:latest" β Creates nginx deploymentResource Management:
"delete pod my-app" β Deletes pod
"delete deployment web-app" β Deletes deployment
"remove pod nginx-pod" β Alternative delete syntaxVague Commands (System interprets intelligently):
"make a pod" β Creates default pod
"deploy something" β Creates default deployment
"show my stuff" β Lists pods
"create nginx" β Creates nginx pod/deployment"How do I request A100 GPUs?" β GPU allocation guide
"What are storage best practices?" β Storage documentation
"How do I run batch jobs?" β Job scheduling guide
"Explain persistent volumes" β PV/PVC conceptsThe package follows Python packaging best practices:
- Clean module separation
- Type hints throughout
- Comprehensive error handling
- Modular design for extensibility
- New K8s Operations: Add functions to
systems/k8s_operations.pyand updateKNOWN_ACTIONSregistry - New Intent Types: Extend
UserIntentenum and classification logic - New Handlers: Create handler functions in
intelligent_router.py - YAML Templates: Add new resource templates in
k8s_operations.pyfor standardized deployments
# Install development dependencies
pip install -e ".[dev]"
# Test basic functionality
python test_integration.py
# Test specific operations
cd nrp_k8s_system
python intelligent_router.py "list pods"
python intelligent_router.py "create pod test-nginx image=nginx"
# Run tests (when available)
pytest
# Code formatting
black nrp_k8s_system/langchain-openai- NRP LLM integrationkubernetes- K8s cluster operationspython-dotenv- Environment configurationopenai- Alternative LLM client
requests,beautifulsoup4- Web scraping (for enhanced features)numpy,scikit-learn- Analytics (for advanced features)pydantic- Data validation
NRP_API_KEY- Required - Your NRP API keyNRP_BASE_URL- NRP LLM endpoint (default: https://llm.nrp-nautilus.io/)NRP_MODEL- Model name (default: gemma3)OPENAI_API_KEY- Fallback OpenAI keyOPENAI_BASE_URL- OpenAI endpoint
- Uses your existing kubectl configuration
- Defaults to 'gsoc' namespace
- Supports both in-cluster and local configurations
-
"NRP_API_KEY not found"
- Ensure
.envfile exists with validNRP_API_KEY - Check environment variable is set
- Ensure
-
"Could not configure Kubernetes client"
- Verify kubectl is installed and configured
- Check cluster connectivity
-
Import errors
- Ensure all dependencies are installed:
pip install -r requirements.txt - Verify Python version >= 3.8
- Ensure all dependencies are installed:
-
Intent classification fails
- System falls back to keyword-based classification
- Check NRP API connectivity
MIT License - see package metadata for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
For issues and questions:
- Check this README and troubleshooting section
- Review the code documentation
- Open an issue in the project repository