Skip to content

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Build a K8s SRE

Page as Markdown

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

Build a K8s SRE

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

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.

Before you begin

  1. Install kagent.
  2. Open the kagent UI with kagent dashboard.

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.

YAML version

Everything that you did in the UI is stored as Kubernetes resources. To create the same resources from the command line, or to keep them in a Git repository, apply this YAML.

The k8s-sre agent, with both sets of tools
kubectl apply -f - <<EOF
apiVersion: api.kagent.dev/v1alpha3
kind: Agent
metadata:
  name: k8s-sre
  namespace: kagent
spec:
  harnessRef:
    name: kagent-default
  template:
    inline:
      description: Kubernetes SRE that investigates before it acts
      modelConfig:
        name: default-model-config
      systemPrompt: |-
        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.
      tools:
        - mcp:
            server:
              kind: RemoteMCPServer
              name: kagent-tool-server
            tools:
              - k8s_get_resources
              - k8s_describe_resource
              - k8s_get_events
              - k8s_get_pod_logs
        - mcp:
            requireApproval: true
            server:
              kind: RemoteMCPServer
              name: kagent-tool-server
            tools:
              - k8s_scale
              - k8s_rollout
EOF

Next steps