Claude Code, Cursor and their kin are good at Kubernetes: they read events, follow a crash back to a config change, and write the patch. The question is how they reach the cluster. The quickest way, letting the agent use the kubeconfig already on your laptop, is also the one that gives it the most.
What your kubeconfig gives an agent
An agent with a shell runs kubectl with whatever KUBECONFIG that shell has. For most engineers that is a context with broad rights, sometimes cluster-admin, across every namespace. It does not expire when the session ends, it cannot tell the agent’s requests from yours, and nothing outside the cluster’s own audit log records what was done with it. A careful prompt is not a permission.
There are better ways, from a few minutes of work to none.
1. A read-only identity of its own
Kubernetes ships a view ClusterRole that reads most objects and not Secrets. Give the agent a service account bound to it and a token that runs out on its own:
kubectl create namespace agents kubectl create serviceaccount claude-reader -n agents kubectl create clusterrolebinding claude-reader-view \ --clusterrole=view --serviceaccount=agents:claude-reader kubectl create token claude-reader -n agents --duration=8h
Put that token in a kubeconfig of its own and start the agent with KUBECONFIG pointing at it. It can now list pods, read events and logs, and describe anything view allows, and nothing else. When you want it to change something, it writes the command and you run it.
The limits: the token is still a file on a laptop, every person sets this up again, and the cluster’s API server must be reachable from where the agent runs.
2. An MCP server on your machine
A local MCP server for Kubernetes gives the agent structured tools (list pods, get logs, describe) instead of a shell. Most read your kubeconfig and offer a read-only switch. Point one at the service account above, not at your own context: the documentation of the common ones calls the read-only switch a guardrail and RBAC the boundary. How the common ones authenticate and what they limit is compared in Kubernetes MCP servers compared.
3. A remote MCP server with a scoped credential
The third way moves the credential off the laptop. Subnomic runs a remote MCP server at app.subnomic.com/mcp; it reaches the cluster through the Subnomic agent already running in it, so there is no kubeconfig on the laptop and no port open on the cluster. You mint one credential per client with:
- capabilities, for example
kube.readandresource.readto look,resource.writeonly when it may restart or scale; - targets: this cluster, not the rest of the workspace;
- an expiry of 7 to 360 days, never none.
claude mcp add --transport http subnomic https://app.subnomic.com/mcp \ --header "Authorization: Bearer $SUBNOMIC_AGENT_TOKEN"
Changes pass the same guardrails as a person’s. A rule such as ^kubernetes\.delete\b.*\bns=prod\b denies a delete in prod, and a rule that requires approval refuses the call outright, because an MCP call has nobody to ask. Each call is logged against the credential with its tool, outcome and duration.
Which one
- Trying it alone on a test cluster: the read-only service account.
- Tools instead of a shell, still on your machine: a local MCP server pointed at that account.
- A team, production clusters, or anyone who will ask later what the agent did: a scoped, expiring remote credential.
Step by step for Claude Code, Cursor and VS Code is in Connect Claude Code or Cursor to Kubernetes. MCP for your own clients is part of Team and Enterprise; the tool list is on the MCP page.