Skip to content
This documentation covers kagent while it is in development and can describe unreleased features. For the current release, see the latest docs.

Build a K8s SRE

Page as Markdown

Build a Kubernetes SRE agent that investigates the cluster on its own and asks for approval before it changes anything.

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.

  1. Install kubectl, helm 3, and kind v0.32.0 or later.

  2. 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.0
  3. Set the API key of your model provider, then install the kagent CLI and run it. kagent install sets 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 install
  4. Check 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 dashboard

The command forwards the UI to http://localhost:8082 and opens it in your browser. Leave it running while you work.

Create the agent

The kagent UI creating an agent named k8s-sre with read-only Kubernetes tools and a second set of tools that require approval
Figure: Creating the k8s-sre agent with two sets of tools, sped up
  1. In the sidebar, click Agents, and then click New Agent.

  2. In the Name field, enter k8s-sre. Leave the Namespace as kagent, and leave Shared harness set to kagent-default.

  3. In the Template section, select Inline, and fill in the template.

    FieldValue
    Model configurationkagent/default-model-config
    DescriptionKubernetes SRE that investigates before it acts
  4. In 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

  1. Under Tools from MCP servers, click Add an MCP server, and choose kagent/kagent-tool-server from the MCP server list.

  2. From the tool list beside it, choose the tools that only read. Type part of a name to find a tool.

    ToolWhat 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

  1. Click Add an MCP server again, and choose kagent/kagent-tool-server a second time.

  2. From the tool list, choose k8s_scale and k8s_rollout.

  3. Select Require approval. The agent now pauses before each of these tools runs, and waits for you to approve or reject the call.

  4. Click Create agent, and then click Refresh until the agent is Ready.

Ask it about the cluster

  1. Click the agent name, k8s-sre, to open its chat page.

  2. Ask a question that the read-only tools can answer, such as Are any pods in the kagent namespace unhealthy?

  3. Ask for a change, such as Scale the kagent-ui deployment to 2 replicas. The agent asks for your approval before it calls k8s_scale.

Verify the agent

  1. Check that the agent is ready.

    kubectl get agent k8s-sre -n kagent

    Example output:

    NAME      READY   AGE
    k8s-sre   True    5m
    
  2. Check 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 true and lists k8s_scale and k8s_rollout.

  3. 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 the k8s_scale call. 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:

FeatureWhat you didRead more
Agents and inline templatesGave the agent its model and SRE prompt in one formAbout agents, System prompts
MCP toolsBound selected tools from the built-in kagent-tool-serverAbout tools, Tools ecosystem
Human in the loopRequired approval on every call to the tools that change the clusterHuman in the loop

Clean up

  1. Delete the agent. The kagent-tool-server is part of your installation, so leave it in place.

    kubectl delete agent k8s-sre -n kagent
  2. If you approved a scale during the tutorial, scale the kagent-ui deployment back to the replica count that it had before.

Next steps