An agent in the cluster, with kagent
kagent is one way to put an agent beside Turf™: the agent runs in the cluster and reaches Turf’s MCP server over HTTP, like any other client. The turf-kagent repository builds the whole setup on a kind cluster: one step makes the engine’s AWS key, and one script does the rest. The cluster is the control plane, and what the agent runs is outside it: a fleet of AWS Lambda functions, which it calls after each rollout to check that the fleet answers.
kagent 1.0 runs the agent in a gVisor sandbox. The engine runs as a Knative service on restate-server, scaling from zero when a round starts and back to zero after. It holds the AWS key, and the agent’s sandbox holds no credential. State stays in the cluster, a Secret per stack. Every apply waits for a person in the kagent UI.
Turf’s side is the minimal set in its operator and Knative form, in the
turf namespace, with an AWS key on the engine and state in a namespace of its own. The rest is
kagent’s. What runs where lists every namespace, and
Agentic IaC for Platform Teams
is the paper that walks one run of this example.
Before you start
Section titled “Before you start”You need Docker, kind v0.32 or later, kubectl, Helm® 3 or later, the kagent CLI 1.0.0, an Anthropic API key and an AWS account. kagent 1.0 needs Kubernetes® 1.37.
Set it up
Section titled “Set it up”-
Install the kagent CLI:
Terminal window curl -fsSL https://raw.githubusercontent.com/kagent-dev/kagent/refs/heads/main/scripts/get-kagent \| bash -s -- --version v1.0.0 -
From a clone of turf-kagent, make the engine’s AWS key with your own AWS session:
Terminal window git clone https://github.com/turfbuild/turf-kagent && cd turf-kagentturf -C setup/aws up # or: tofu -chdir=setup/aws init && tofu -chdir=setup/aws apply -
Create a kind cluster and run the setup:
Terminal window kind create cluster --name turf-kagent --image kindest/node:v1.37.0export ANTHROPIC_API_KEY=..../setup/up.sh
setup/aws creates an IAM user, turf-kagent-engine, with one policy and one access key, and writes
the key to .secrets/, which git ignores. The policy covers Lambda functions in one region and IAM
roles, both only under names that start with turf-kagent-, and nothing else in the account.
setup/up.sh runs four setup scripts in order: Knative Serving with Kourier, the Restate operator,
kagent, and the Secrets. Then it applies manifests/turf and manifests/kagent and waits for the
agent. Every step is safe to run again. It refuses a kubectl context that is not a kind cluster unless
you set FORCE=1.
How the agent reaches Turf
Section titled “How the agent reaches Turf”kagent lists Turf’s tools from a RemoteMCPServer. The bearer token comes from a Secret named in
headersFrom:
apiVersion: api.kagent.dev/v1alpha3kind: RemoteMCPServermetadata: name: turf namespace: kagentspec: url: http://turf-mcp-server.turf.svc.cluster.local:3000/mcp protocol: STREAMABLE_HTTP # A call gets five minutes, and the server answers within its --deadline (4m). Both are long so # that an apply in AWS ends inside one call: kagent asks for approval on every apply call. timeout: 5m0s sseReadTimeout: 10m0s headersFrom: - name: Authorization valueFrom: type: Secret name: turf-mcp-auth key: authorizationThe turf-mcp-auth Secret in the kagent namespace holds the whole header value, Bearer included,
and kagent sends it as it is. kagent’s controller reads the Secret to list the tools. The agent never
holds it: its sandbox sends a placeholder, and Agent Substrate’s egress gateway puts the real value in
on the way out. The Anthropic key travels the same way. The server’s NetworkPolicy admits only kagent’s
controller and the egress gateway.
What the agent runs, and who holds what
Section titled “What the agent runs, and who holds what”The configuration comes from the examples image, ghcr.io/turfbuild/turf-examples:1.0.0: the
turf-examples repository, mounted read-only at
/turf/examples in the server’s pod and every engine pod. The agent gives Turf a path inside it,
terraform/aws/lambda-fleet:
one execution role, a fleet of Lambda functions, a public URL for each, and a turf action that verifies
the rollout. The agent operates the configuration and does not edit it. A change is a new image version.
- The engine holds the AWS key, in the
turf-awsSecret that only its pods mount. Its ServiceAccount is bound to no Role, so it changes nothing in the cluster it runs in. - The agent holds no cloud credential, and it has no Kubernetes tools to fetch one with. kagent’s
built-in tool server runs as
cluster-admin, so this agent does not bind it. - State has a namespace of its own,
kagent-tfstate: a Secret and a Lease per stack. The server’s Role covers that namespace and nothing else, so the server cannot read the Secrets inturf. - The sandbox’s egress is denied by default. The egress gateway allows the model and the Agent’s
MCP servers because they are named. An
EgressPolicythat the Agent selects adds one more origin,https://*.lambda-url.us-west-2.on.aws: the public URLs of Lambda functions in one region. The AWS API is not on the list.
Approvals
Section titled “Approvals”The agent’s tools come in three bindings:
- Turf’s calls that change nothing on their own:
init,open,up,destroy,plan,showand the rest. They run freely. They can start a round and plan it, and the round then waits at its approval point. - Turf’s four calls that change infrastructure or state,
apply,taint,untaintanddelete, bound withrequireApproval: true. - The OpenTofu® Registry’s documentation tools, each named.
Each of the four pauses the agent until a person approves it in the kagent UI. apply carries the
digest of the plan it applies, so the approval covers exactly that plan. kagent’s approval request
shows only the call’s arguments: the convergence and the digest. The agent’s prompt has it call show
right before apply, so the plan is the result just above the request. It is also the round’s Plan tab
in the console. Reject with a reason and nothing is applied: the reason reaches the agent, which
cancels the convergence, freeing the stack’s lock, and asks what you want instead.
The configuration also declares a turf action, verify: a step of the apply that the agent carries out
instead of a provider. After the fleet is created or patched, the apply pauses, and the agent fetches
every function’s URL from its sandbox and checks that each answers with the declared greeting. It
reports the result through apply again, so kagent asks for a second approval.
Run it
Section titled “Run it”In one terminal, watch the engine. It sits at zero:
kubectl get pods -n turf -l app=turf-engine -wIn two more, forward the kagent UI and the Turf console:
kubectl port-forward -n kagent svc/kagent-ui 8082:8080 # http://localhost:8082kubectl port-forward -n turf svc/turf-console 8873Pick the agent turf in the kagent UI, and sign in to the console once with its token:
open "http://localhost:8873/login?token=$(cat .secrets/console-token)"Then ask the agent:
-
“Deploy the Lambda fleet as a stack called demo.” The agent loads Turf’s deployment skill, runs
initon/turf/examples/terraform/aws/lambda-fleet, opens workspacedemoon the kubernetes backend, startsupwith the stack’s variables (two functions,turf-kagent-demo-0andturf-kagent-demo-1), plans, and stops at the approval point. Engine pods appear in the first terminal as soon as it opens the workspace. kagent asks you to approveapply. The plan is 9 to add: the execution role and its policy attachment, two functions, a URL and a permission for each, and the rollout marker. Approve, and the apply pauses at the turf action: the agent fetches both URLs and reports back throughapply. Approve that too. The engine pods go away a minute or so after the round ends, and the functions answer anyone:Terminal window curl https://<id>.lambda-url.us-west-2.on.aws/# {"message":"Hello from the cluster.","function":"turf-kagent-demo-0"} -
“Change demo’s greeting to ‘Patched from the cluster.’” A second plan: two updates in place and the rollout marker. You approve it, the agent fetches both URLs again and reports the new greeting, and you approve that report.
-
“What is in demo?” Read-only, no pause. The agent reads the stack’s state through Turf. Ask it for the AWS key, or any Secret, and it cannot get one. To see every stack yourself, run
kubectl get leases -n kagent-tfstate: there is one Lease per stack. -
“Tear down the demo stack.” kagent asks for approval again, this time for a destroy plan. Reject it with a reason and nothing is applied. Ask again and approve, and the fleet is gone.
Restate’s UI shows each round’s invocations: kubectl port-forward -n turf svc/restate 9070, then
http://localhost:9070.
Other clients
Section titled “Other clients”The agent is an A2A endpoint on kagent’s controller, so anything that speaks A2A can drive it. To
answer an approval, a client requests the extension https://kagent.dev/extensions/hitl/v1 (header
A2A-Extensions) and replies with a tool_approval_response. kagent also serves its Sessions over
MCP, so Claude Code can talk to the same agent:
kubectl port-forward -n kagent svc/kagent-controller 8083:8083curl -s http://localhost:8083/agents/kagent/turf/.well-known/agent-card.json # the A2A agent cardclaude mcp add --transport http kagent http://localhost:8083/mcp # Sessions, over MCPThings to know
Section titled “Things to know”- The token crosses the cluster network in cleartext, from the egress gateway to the server over
http://. Serve the server over TLS, or run a mesh, where that matters. - The server can read every Secret in
kagent-tfstate, so keep nothing else there (Credentials in a cluster). The namespace is named in three places that must agree:namespace.yaml, the Role inmcp-server.yaml, andbackend_config.namespacein the agent’s prompt. - The engine’s AWS key is the demo’s: a long-lived key for Lambda functions and IAM roles named
turf-kagent-*. Widen the policy insetup/awsto what your configurations declare. Where the cluster has a cloud identity, give the engine’s ServiceAccount a role instead of a key. - Scale from zero has a cost. Each new engine pod installs providers and modules the first time a step lands on it.
- Versions. kagent 1.0.0, Knative Serving 1.24.0 with Kourier, the Restate operator 3.2.0, restate-server 1.8.1 and Turf 1.4.0, on kind with Kubernetes 1.37.0.
Clean up
Section titled “Clean up”The fleets are in AWS, not in the cluster. Tear the stacks down first (ask the agent, and approve each destroy), then delete the cluster, then the engine’s IAM user and key:
kind delete cluster --name turf-kagentturf -C setup/aws destroyLambda leaves a CloudWatch log group, /aws/lambda/<function>, for every function that was called.
The configuration does not declare them, so remove them by hand for a clean account.
What runs where
Section titled “What runs where”| Namespace | What |
|---|---|
kagent |
the controller and UI; the WorkerPool the agent’s sandbox runs on; the agent’s Harness, AgentTemplate and Agent; a ModelConfig for Anthropic; RemoteMCPServers for Turf and the OpenTofu Registry; the EgressPolicy |
ate-system |
Agent Substrate’s control plane, and the egress gateway every connection from the sandbox goes through |
turf |
restate-server, the MCP server, the engine, the console, and their Secrets |
kagent-tfstate |
the state of the agent’s stacks and nothing else: a Secret and a Lease per stack |
knative-serving, kourier-system |
Knative Serving and its Kourier gateway |
restate-operator |
the Restate operator |
The repository’s README is the full reference: every control between the parts, a check for each, and the rest of the notes.
Turf™ is a trademark of Turf LLC. Terraform® is a trademark of HashiCorp. Ansible® is a trademark of Red Hat, LLC, registered in the United States and other countries. Helm®, Kubernetes®, Prometheus® and OpenTelemetry® are registered trademarks, and Jaeger™ is a trademark, of the Linux Foundation. OpenTofu® and Model Context Protocol® are registered trademarks of LF Projects, LLC. All other trademarks are the property of their respective owners. Turf is not affiliated with, endorsed by, or sponsored by HashiCorp, IBM, Red Hat, the Linux Foundation, LF Projects or the OpenTofu project.
© 2026 Turf LLC. Free for individuals, education and small businesses within the Community limits, under the Turf Community Edition License 1.0. Government and larger organizations need a commerciallicense.turf.build · Discord ·GitHub