kubectl-ai - AI Assistant for Kubernetes Cheatsheet
kubectl-ai is an AI-powered assistant for Kubernetes (from Google Cloud) that interprets natural-language requests and translates them into kubectl operations. It can explain what is running, generate manifests, diagnose failing pods, and chain multi-step investigations — running as an interactive agent or a one-shot command. It is model-agnostic: Gemini, OpenAI, or a local model via Ollama, which matters when you would rather not send cluster details to a hosted API.
The agent can execute cluster operations. Review what it proposes before approving anything destructive, and prefer read-only contexts when exploring.
Installation
Model Configuration
| Backend | Setup |
|---|
| Gemini | export GEMINI_API_KEY=... (default) |
| OpenAI | export OPENAI_API_KEY=... and --llm-provider=openai |
| Ollama (local) | --llm-provider=ollama --model=llama3.1 |
| Azure OpenAI | provider + endpoint env vars |
| Grok / others | supported provider flags |
# Fully local — no cluster data leaves the machine
kubectl-ai --llm-provider=ollama --model=gemma3:12b
Usage Modes
| Mode | Command |
|---|
| Interactive | kubectl-ai (chat session) |
| One-shot | kubectl-ai "list pods not in Running state" |
| Piped input | cat error.log | kubectl-ai "what is failing here?" |
| As a plugin | kubectl ai "scale the api deployment to 5" |
What It Handles Well
| Task | Example prompt |
|---|
| Inspection | ”which pods restarted in the last hour?” |
| Diagnosis | ”why is the checkout deployment not ready?” |
| Manifest generation | ”create a deployment for nginx with 3 replicas and a service” |
| Explanation | ”explain what this CRD does” |
| Multi-step triage | ”find failing pods and show their recent logs” |
| Resource math | ”which namespaces use the most CPU requests?” |
Interactive Session Commands
| Command | Does |
|---|
models | List available models |
model <name> | Switch model mid-session |
clear | Reset the conversation |
exit / quit | Leave the session |
| Follow-ups | Ask in context: “now show me its logs” |
Safety Controls
| Control | Purpose |
|---|
| Confirmation prompts | Approve commands before execution |
--quiet | Non-interactive (scripting; use carefully) |
| Read-only kubeconfig context | Strongest guardrail |
| Namespace scoping | Limit blast radius |
| Review generated YAML | Before kubectl apply |
The most reliable safety measure is not a flag — it is pointing the tool at a context whose credentials cannot mutate production.
MCP Integration
kubectl-ai can operate as an MCP server or client, exposing Kubernetes operations as tools to other AI clients (or consuming external MCP tools during a session).
| Mode | Flag |
|---|
| MCP server | --mcp-server |
| MCP client | configure external MCP servers |
Practical Workflow
# Triage a failing service, locally hosted model
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?
Treat the output as a knowledgeable suggestion, not an authority — verify the underlying kubectl output it cites.
| Aspect | kubectl-ai | k9s | kubectl + docs |
|---|
| Interface | Natural language | TUI | Manual commands |
| Diagnosis help | Yes (reasoning) | Visual inspection | Your own knowledge |
| Local model option | Yes (Ollama) | N/A | N/A |
| Best for | Explaining/diagnosing, drafting YAML | Fast cluster navigation | Precise control |
Complements k9s for navigation and kubectl for exact operations.
Resources