kubectl-ai - KI-Assistent für Kubernetes Cheatsheet
kubectl-ai ist ein KI-powered Assistent für Kubernetes (von Google Cloud), der natürlichsprachliche Anfragen interpretiert und sie in kubectl-Operationen übersetzt. Er kann erklären, was läuft, Manifeste generieren, fehlgeschlagene Pods diagnostizieren und Multi-Step-Untersuchungen verketten — läuft als interaktive Agent oder als One-Shot-Befehl. Er ist modell-agnostisch: Gemini, OpenAI oder ein lokales Modell via Ollama, was wichtig ist, wenn du lieber keine Cluster-Details an eine gehostete API sendest.
Der Agent kann Cluster-Operationen ausführen. Überprüfe, was er vorschlägt, bevor du irgendetwas Destruktives genehmigst, und bevorzuge schreibgeschützte Kontexte, wenn du explorierst.
Installation
Modell-Konfiguration
| Backend | Setup |
|---|
| Gemini | export GEMINI_API_KEY=... (Standard) |
| OpenAI | export OPENAI_API_KEY=... und --llm-provider=openai |
| Ollama (lokal) | --llm-provider=ollama --model=llama3.1 |
| Azure OpenAI | Provider + Endpoint Env-Vars |
| Grok / andere | Unterstützte Provider-Flags |
# Vollständig lokal — keine Cluster-Daten verlässt die Machine
kubectl-ai --llm-provider=ollama --model=gemma3:12b
Nutzungs-Modi
| Modus | Befehl |
|---|
| Interaktiv | kubectl-ai (Chat-Sitzung) |
| One-Shot | kubectl-ai "list pods not in Running state" |
| Piped Input | cat error.log | kubectl-ai "what is failing here?" |
| Als Plugin | kubectl ai "scale the api deployment to 5" |
Was es gut handhabt
| Aufgabe | Beispiel-Prompt |
|---|
| Inspection | ”which pods restarted in the last hour?” |
| Diagnose | ”why is the checkout deployment not ready?” |
| Manifest-Generierung | ”create a deployment for nginx with 3 replicas and a service” |
| Erklärung | ”explain what this CRD does” |
| Multi-Step-Triage | ”find failing pods and show their recent logs” |
| Resource-Mathe | ”which namespaces use the most CPU requests?” |
Interaktive Sitzungs-Befehle
| Befehl | Tut |
|---|
models | Liste verfügbare Modelle auf |
model <name> | Wechsele Modell mid-session |
clear | Setzt die Konversation zurück |
exit / quit | Beende die Sitzung |
| Follow-ups | Frage im Kontext: “now show me its logs” |
Sicherheits-Kontrollen
| Kontrolle | Zweck |
|---|
| Bestätigungs-Aufforderungen | Genehmige Befehle vor Ausführung |
--quiet | Non-Interactive (Scripting; mit Vorsicht) |
| Schreibgeschützte Kubeconfig-Context | Stärkste Schutzschiene |
| Namespace-Scoping | Limitiere Blast-Radius |
| Review generiertes YAML | Vor kubectl apply |
Die zuverlässigste Sicherheitsmaßnahme ist nicht ein Flag — sie zeigt das Tool auf einen Kontext, dessen Anmeldedaten Produktion nicht mutieren können.
MCP-Integration
kubectl-ai kann als MCP-Server oder Client fungieren und Kubernetes-Operationen als Tools für andere KI-Clients exponieren (oder externe MCP-Tools während einer Sitzung konsumieren).
| Modus | Flag |
|---|
| MCP-Server | --mcp-server |
| MCP-Client | Externe MCP-Server konfigurieren |
Praktischer Workflow
# Triage einen fehlgeschlagenen Service, lokal gehostetes Modell
kubectl-ai --llm-provider=ollama --model=llama3.1
> why are pods in the payments namespace crashlooping?
> show me the last 50 log lines from the worst offender
> what would you change in the resource limits?
Behandle die Ausgabe als einen wissenden Vorschlag, nicht als Autorität — verifiziere die zugrundeliegende kubectl-Ausgabe, die es zitiert.
| Aspekt | kubectl-ai | k9s | kubectl + docs |
|---|
| Interface | Natürlichsprache | TUI | Manuelle Befehle |
| Diagnose-Hilfe | Ja (Reasoning) | Visuelle Inspektionen | Dein eigenes Wissen |
| Lokales Modell-Option | Ja (Ollama) | N/A | N/A |
| Bestes für | Erklären/Diagnostizieren, YAML-Entwurf | Schnelle Cluster-Navigation | Genaue Kontrolle |
Ergänzt k9s für Navigation und kubectl für genaue Operationen.
Ressourcen