Skip to content

kubectl-ai - AI Assistant for Kubernetes Cheatsheet

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

MethodCommand
Install script`curl -sSL https://raw.githubusercontent.com/GoogleCloudPlatform/kubectl-ai/main/install.sh
Krewkubectl krew install ai
Homebrewbrew install kubectl-ai
Binarydownload from GitHub Releases
Verifykubectl-ai --version

Model Configuration

BackendSetup
Geminiexport GEMINI_API_KEY=... (default)
OpenAIexport OPENAI_API_KEY=... and --llm-provider=openai
Ollama (local)--llm-provider=ollama --model=llama3.1
Azure OpenAIprovider + endpoint env vars
Grok / otherssupported provider flags
# Fully local — no cluster data leaves the machine
kubectl-ai --llm-provider=ollama --model=gemma3:12b

Usage Modes

ModeCommand
Interactivekubectl-ai (chat session)
One-shotkubectl-ai "list pods not in Running state"
Piped inputcat error.log | kubectl-ai "what is failing here?"
As a pluginkubectl ai "scale the api deployment to 5"

What It Handles Well

TaskExample 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

CommandDoes
modelsList available models
model <name>Switch model mid-session
clearReset the conversation
exit / quitLeave the session
Follow-upsAsk in context: “now show me its logs”

Safety Controls

ControlPurpose
Confirmation promptsApprove commands before execution
--quietNon-interactive (scripting; use carefully)
Read-only kubeconfig contextStrongest guardrail
Namespace scopingLimit blast radius
Review generated YAMLBefore 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).

ModeFlag
MCP server--mcp-server
MCP clientconfigure 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.

Aspectkubectl-aik9skubectl + docs
InterfaceNatural languageTUIManual commands
Diagnosis helpYes (reasoning)Visual inspectionYour own knowledge
Local model optionYes (Ollama)N/AN/A
Best forExplaining/diagnosing, drafting YAMLFast cluster navigationPrecise control

Complements k9s for navigation and kubectl for exact operations.

Resources