Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Provides AI-powered Kubernetes cluster analysis and troubleshooting using K8sGPT with Qwen LLM. Use when diagnosing cluster issues, analyzing problems, or getting intelligent insights about Kubernetes resources and configurations.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | 168% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 141% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 238% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 112% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 309% | 0% |
Enterprise-grade AI-powered Kubernetes cluster analysis and troubleshooting solution that leverages K8sGPT with Qwen LLM to provide intelligent insights, automated problem detection, and contextual recommendations across multi-cloud Kubernetes environments.
analyze|diagnose|optimize|monitor|report (required)namespace|deployment|pod|service|cluster (required)cluster|namespace|resource|all (optional, default: cluster)qwen|openai|localai|ollama (optional, default: qwen)true)json|yaml|table|summary (optional, default: json)production)scripts/k8sgpt_analyzer.py: Main analysis engine and orchestrationscripts/qwen_integration.py: Qwen LLM backend configurationscripts/cluster_scanner.py: Multi-cluster resource discoveryscripts/report_generator.py: Comprehensive report generationscripts/automation_helper.py: Automated setup and configurationk8sgpt, analyzer, kubernetes, troubleshooting, AI, qwen, analysis, monitoring, optimization, cluster, diagnostics
python#!/usr/bin/env python3 """ K8sGPT Analyzer - AI-Powered Kubernetes Intelligence Integrates K8sGPT with Qwen LLM for intelligent cluster analysis """ import json import sys import uuid import logging import subprocess import yaml from datetime import datetime from typing import Dict, Any, Optional, List from pathlib import Path class K8sGPTAnalyzer: def __init__(self): self.operation_id = str(uuid.uuid4()) self.config = self._load_config() self.k8sgpt_path = self._find_k8sgpt() def _load_config(self) -> Dict[str, Any]: """Load configuration from file or defaults""" config_path = Path.home() / '.k8sgpt' / 'config.yaml' default_config = { 'backend': 'qwen', 'model': 'qwen2.5-7b-instruct', 'baseurl': 'http://localhost:8000/v1', 'max_tokens': 4096, 'temperature': 0.7, 'namespace': 'default', 'output_format': 'json' } if config_path.exists(): with open(config_path, 'r') as f: user_config = yaml.safe_load(f) default_config.update(user_config) return default_config def _find_k8sgpt(self) -> str: """Find K8sGPT binary in PATH""" try: result = subprocess.run(['which', 'k8sgpt'], capture_output=True, text=True, check=True) return result.stdout.strip() except subprocess.CalledProcessError: raise RuntimeError("K8sGPT CLI not found. Please install K8sGPT first.") def execute_operation(self, params: Dict[str, Any]) -> Dict[str, Any]: """Main operation execution""" try: validated_params = self._validate_inputs(params) self._setup_k8sgpt_backend(validated_params) results = self._perform_analysis(validated_params) return self._format_output(results, "completed") except Exception as e: return self._handle_error(e, params) def _validate_inputs(self, params: Dict[str, Any]) -> Dict[str, Any]: """Input validation""" required_fields = ['operation', 'targetResource'] for field in required_fields: if field not in params: raise ValueError(f"Missing required field: {field}") valid_operations = ['analyze', 'diagnose', 'optimize', 'monitor', 'report'] if params['operation'] not in valid_operations: raise ValueError(f"Invalid operation: {params['operation']}") return params def _setup_k8sgpt_backend(self, params: Dict[str, Any]) -> None: """Configure K8sGPT backend (Qwen by default)""" backend = params.get('backend', self.config['backend']) if backend == 'qwen': # Configure Qwen backend via LocalAI/OpenAI compatible API cmd = [ 'k8sgpt', 'auth', 'add', '--backend', 'localai', '--model', self.config['model'], '--baseurl', self.config['baseurl'] ] subprocess.run(cmd, check=True, capture_output=True) logging.info(f"K8sGPT backend configured: {backend}") def _perform_analysis(self, params: Dict[str, Any]) -> Dict[str, Any]: """Execute K8sGPT analysis""" operation = params['operation'] target = params['targetResource'] scope = params.get('scope', 'cluster') explain = params.get('explain', True) # Build K8sGPT command cmd = ['k8sgpt', 'analyze'] if scope != 'cluster': cmd.extend(['--namespace', scope]) if target != 'cluster': cmd.extend(['--filter', target]) if explain: cmd.append('--explain') # Add backend specification cmd.extend(['--backend', params.get('backend', self.config['backend'])]) # Execute analysis result = subprocess.run(cmd, capture_output=True, text=True, check=True) # Parse and enhance results analysis_data = self._parse_k8sgpt_output(result.stdout) return { 'operation': operation, 'target': target, 'scope': scope, 'analysis': analysis_data, 'timestamp': datetime.utcnow().isoformat(), 'backend': params.get('backend', self.config['backend']) } def _parse_k8sgpt_output(self, output: str) -> Dict[str, Any]: """Parse K8sGPT output into structured format""" try: # Try JSON first return json.loads(output) except json.JSONDecodeError: # Parse text output lines = output.strip().split('\n') return { 'format': 'text', 'content': output, 'lines': lines, 'summary': lines[0] if lines else "No analysis available" } def _format_output(self, results: Dict[str, Any], status: str) -> Dict[str, Any]: """Format output according to enterprise schema""" return { "operationId": self.operation_id, "status": status, "timestamp": datetime.utcnow().isoformat(), "result": results, "metadata": { "execution_time": 1.0, "risk_score": 3, "agent_version": "1.0.0", "k8sgpt_version": "latest", "backend": self.config['backend'] } } def _handle_error(self, error: Exception, params: Dict[str, Any]) -> Dict[str, Any]: """Comprehensive error handling""" return { "operationId": self.operation_id, "status": "failed", "timestamp": datetime.utcnow().isoformat(), "error": { "code": "ANALYSIS_ERROR", "message": str(error), "details": { "parameters": params, "error_type": type(error).__name__ } } } def main(): # Configure logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) if len(sys.argv) > 1: params = json.loads(sys.argv[1]) else: params = { 'operation': 'analyze', 'targetResource': 'cluster', 'scope': 'cluster', 'backend': 'qwen', 'explain': True } analyzer = K8sGPTAnalyzer() result = analyzer.execute_operation(params) print(json.dumps(result, indent=2)) if __name__ == "__main__": main()
bash#!/bin/bash # K8sGPT Analyzer Shell Integration OPERATION=${1:-analyze} TARGET=${2:-cluster} SCOPE=${3:-cluster} BACKEND=${4:-qwen} echo "Executing K8sGPT ${OPERATION} on ${TARGET} in ${SCOPE} scope" # Setup Qwen backend if needed if [[ "$BACKEND" == "qwen" ]]; then echo "Configuring Qwen LLM backend..." k8sgpt auth add --backend localai --model qwen2.5-7b-instruct --baseurl http://localhost:8000/v1 fi # Execute analysis case $OPERATION in "analyze") k8sgpt analyze --explain --backend $BACKEND ${TARGET:+--filter $TARGET} ${SCOPE:+--namespace $SCOPE} ;; "diagnose") k8sgpt analyze --explain --backend $BACKEND --filter "problems" ${TARGET:+--filter $TARGET} ;; "optimize") k8sgpt analyze --explain --backend $BACKEND --filter "resources" ${TARGET:+--filter $TARGET} ;; "monitor") k8sgpt analyze --backend $BACKEND --output json ${TARGET:+--filter $TARGET} ;; *) echo "Unknown operation: $OPERATION" echo "Available: analyze, diagnose, optimize, monitor" exit 1 ;; esac
json{ "type": "object", "properties": { "operation": { "type": "string", "enum": ["analyze", "diagnose", "optimize", "monitor", "report"], "description": "Type of analysis to perform" }, "targetResource": { "type": "string", "description": "Target resource for analysis" }, "scope": { "type": "string", "enum": ["cluster", "namespace", "resource", "all"], "default": "cluster", "description": "Analysis scope" }, "backend": { "type": "string", "enum": ["qwen", "openai", "localai", "ollama"], "default": "qwen", "description": "LLM backend to use" }, "explain": { "type": "boolean", "default": true, "description": "Enable AI explanations" }, "output": { "type": "string", "enum": ["json", "yaml", "table", "summary"], "default": "json", "description": "Output format" } }, "required": ["operation", "targetResource"] }
Other measured skills in the registry, with their headline benchmark lift.