Skip to content
Subnomic
← Back to blog
AI Nov 13, 2026 · Updated Nov 22, 2026 · 3 min read

Claude Code and Kubernetes, without your kubeconfig

The quickest way to connect an agent to a cluster is the one that gives it the most. There are better ones.

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.

Three ways an AI client reaches a Kubernetes cluster One: Claude Code uses your kubeconfig and reaches the API server with your rights and no expiry. Two: it uses a service account bound to the view role, with a token that expires. Three: it calls Subnomic's MCP server with a credential that names capabilities, targets and an expiry; the Subnomic agent inside the cluster dials out to Subnomic and talks to the API server, with guardrails checked and every call logged. 1 · Your kubeconfig Claude Code your rights, no expiry API server 2 · A read-only service account Claude Code view role, token expires API server 3 · A scoped remote credential Claude Code Subnomic MCP capabilities · targets expiry · guardrails every call logged your cluster API server Subnomic agent the agent dials out; no kubeconfig on the laptop
The further down, the less the agent holds: your own access, a read-only identity, or a credential that names what it may do, where, and until when.

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:

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

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.