Build a K8s SRE
Build a Kubernetes SRE agent that investigates the cluster on its own and asks for approval before it changes anything.
About this tutorial
Build an agent that works like a careful site reliability engineer. It reads the cluster on its own to find out what is wrong, and it stops to ask you before it changes anything.
kagent installs an MCP server, kagent-tool-server, with tools for Kubernetes. You give the agent two sets of those tools: read-only tools that it can call freely, and tools that change the cluster, which need your approval on every call. For how a tool call pauses for a person, see Human in the loop. For how an agent is put together, see About agents.
Time: about 15 minutes.
Before you begin
If kagent already runs in your cluster, skip these steps.
Create a local kind cluster. To use a Kubernetes cluster that you already run, at version 1.37 or later, skip this step.
kind create cluster --name kagent --image kindest/node:v1.37.0Set the API key of your model provider, then install the kagent CLI and run it.
kagent installsets up the CRDs, Agent Substrate, a development PostgreSQL database, and kagent, and takes a few minutes.export OPENAI_API_KEY="your-api-key-here" curl -sL https://kagent.dev/install | bash && kagent installCheck that the kagent pods run. Every pod reports
Running.kubectl get pods -n kagent
Build the SRE agent
Build the agent step by step in the kagent UI, or apply the same resources as YAML and talk to the agent with the kagent CLI.
Open the kagent UI
kagent dashboardThe command forwards the UI to http://localhost:8082 and opens it in your browser. Leave it running while you work.
Create the agent

In the sidebar, click Agents, and then click New Agent.
In the Name field, enter
k8s-sre. Leave the Namespace askagent, and leave Shared harness set tokagent-default.In the Template section, select Inline, and fill in the template.
Field Value Model configuration kagent/default-model-configDescription Kubernetes SRE that investigates before it actsIn the System prompt field, enter the following prompt.
You are a Kubernetes site reliability engineer. Investigate with your read-only tools before you suggest a change. Explain what you found, then propose the smallest fix. Never guess. When the tools cannot answer, say so.
Give it read-only tools
Under Tools from MCP servers, click Add an MCP server, and choose
kagent/kagent-tool-serverfrom the MCP server list.From the tool list beside it, choose the tools that only read. Type part of a name to find a tool.
Tool What it does k8s_get_resourcesLists resources, such as pods and deployments. k8s_describe_resourceDescribes one resource. k8s_get_eventsReads events. k8s_get_pod_logsReads the logs of a pod. Leave Require approval cleared for this set.
Give it tools that need approval
Click Add an MCP server again, and choose
kagent/kagent-tool-servera second time.From the tool list, choose
k8s_scaleandk8s_rollout.Select Require approval. The agent now pauses before each of these tools runs, and waits for you to approve or reject the call.
Click Create agent, and then click Refresh until the agent is Ready.
Ask it about the cluster
Click the agent name,
k8s-sre, to open its chat page.Ask a question that the read-only tools can answer, such as
Are any pods in the kagent namespace unhealthy?Ask for a change, such as
Scale the kagent-ui deployment to 2 replicas.The agent asks for your approval before it callsk8s_scale.
Verify the agent
Check that the agent is ready.
kubectl get agent k8s-sre -n kagentExample output:
NAME READY AGE k8s-sre True 5mCheck that the agent binds both sets of tools, and that only the second set requires approval.
kubectl get agent k8s-sre -n kagent \ -o jsonpath='{range .spec.template.inline.tools[*]}{.mcp.requireApproval}{" "}{.mcp.tools}{"\n"}{end}'The first line lists the four read-only tools with no approval flag. The second line starts with
trueand listsk8s_scaleandk8s_rollout.On the agent’s chat page in the kagent UI, ask for a change, such as
Scale the kagent-ui deployment to 2 replicas.The agent stops and asks you to approve or reject thek8s_scalecall. Reject it to leave the deployment as it is.
What you built
An agent that investigates the cluster freely and asks before it changes anything. Along the way, you used these features:
| Feature | What you did | Read more |
|---|---|---|
| Agents and inline templates | Gave the agent its model and SRE prompt in one form | About agents, System prompts |
| MCP tools | Bound selected tools from the built-in kagent-tool-server | About tools, Tools ecosystem |
| Human in the loop | Required approval on every call to the tools that change the cluster | Human in the loop |
Clean up
Delete the agent. The
kagent-tool-serveris part of your installation, so leave it in place.kubectl delete agent k8s-sre -n kagentIf you approved a scale during the tutorial, scale the
kagent-uideployment back to the replica count that it had before.