AI agents for Kubernetes: how they work, how to keep them safe
What a troubleshooting agent actually does, the tools it needs, and the guard rails that stop it becoming the incident.
An AI agent for Kubernetes works like a careful on-call engineer: look, think, look again, then propose. The model decides which tool to call next; your code runs the tool against the cluster and hands back the result. The loop ends with a diagnosis and a suggested fix, and, if allowed, a change a person has approved.
Agents are good at the tedious part of troubleshooting: reading events, matching error messages to causes, and connecting a pod's logs with its ConfigMap or limits. They're bad at knowing when they're wrong, and they read text that anyone can write (application logs, annotations, events), which can carry instructions aimed at the model (prompt injection).
So the design does the protecting: least-privilege Kubernetes roles, read-only diagnosis, a short list of narrow fix tools, human approval for every change, no access to the agent's own permissions or system namespaces, trimmed tool output, logged tool calls and a cap on tokens. Tool protocols such as MCP (Model Context Protocol) let assistants reuse ready-made Kubernetes tool servers, but the same rules apply to them.
Cost. Model calls are charged per token by the provider; a typical diagnosis costs pennies if tool output is trimmed. The cluster can be a free kind cluster.
Use it when
- on-call engineers spend most of an incident gathering the same evidence.
- you want a first diagnosis before a person looks.
- you want to learn how agentic AI is built and governed in operations.
How it works
- Tools
- Small functions with clear inputs: list pods, describe, events, logs (tail), get spec. The model only chooses among them.
- Loop
- Model chooses a tool, code runs it, the result goes back, repeat until done or a limit is hit.
- Read-only diagnosis
- A role with get, list and watch only. The agent can look everywhere it needs and change nothing.
- Approved fixes
- Separate write tools that show the exact change and wait for a person. Narrow scope, no system namespaces.
- Observability
- Log every tool call, its arguments and output size; cap calls and tokens per question.
Options
- Read-only assistant
- Lowest risk: it diagnoses and suggests, a person does the fix.
- Approve-then-act agent
- It applies a change after a person approves the exact action.
- Fully automatic
- Only for narrow, well-tested fixes with strong limits; most teams don't start here.
Example. Tollmere Logistics piloted a read-only agent for a month. It gave the right first diagnosis in most CrashLoopBackOff and ImagePullBackOff incidents, cut time to first diagnosis, and never changed anything. They then added one approved fix tool (raise a memory limit within a set maximum) and kept everything else manual.
Don't confuse it with
- Runbook automation
- Fixed steps for a known problem. An agent chooses steps, so it needs tighter guard rails.
- kubectl plugins and dashboards
- Show you the evidence; an agent also reads it and explains it.
Words to know
- Tool calling
- The model asks your code to run a named function with given arguments.
- MCP
- Model Context Protocol: a standard way to offer tools to AI assistants.
- Prompt injection
- Text in the data the agent reads that tries to give the model new instructions.
- Blast radius
- How much damage a mistake or a compromised agent could do.
Where to look
- kubectl
- Azure AI Foundry
- Agent code
Practise it
- Build a safe AI troubleshooting agent for KubernetesHow-to, Costs money
- Fix pods that won't startHow-to, Free
- Use AI in pipelines safelyHow-to, Free
Read it in the guide, next to the tasks and labs.
Open in DevOps, Hands On