In this guide, you give an MCP client access to a Kubernetes cluster that is enrolled in Teleport. The client runs the open source kubernetes-mcp-server, which talks to the Kubernetes API through Teleport with a short-lived Teleport certificate. The client never sees a cluster token or a long-lived kubeconfig.
Language models can call any tool the MCP server offers, so the agent gets a read-only role. Teleport allows only read verbs, Kubernetes RBAC allows only the built-in view permissions, and the MCP server runs in read-only mode.
You connect in one of two ways:
- From your dev computer: your MCP client runs locally, and
tsh kube loginpoints it at the cluster. - From inside a beam: your agent runs in a beam, which reaches the cluster with the role you delegate to it.
How it works
- The Teleport Kubernetes Service runs next to your cluster and connects out to Teleport. Beams can’t run a Kubernetes cluster, so the cluster runs on your own infrastructure.
- Your MCP client starts
kubernetes-mcp-serveras a local stdio server. The server reads the kubeconfig thattshwrites, which sends every request to the Teleport proxy. - When the client calls a tool, the server makes Kubernetes API requests. Teleport checks your roles for the cluster, the resource and the verb, then forwards the request, impersonating the Kubernetes groups in your role. Kubernetes RBAC applies on top.
Teleport records each Kubernetes API request as a kube.request event in the audit log. Unlike the internal services and databases guides, Teleport doesn’t see MCP tool calls here. It enforces access at the Kubernetes API.
Prerequisites
- A cluster with Teleport Beams enabled.
- A Kubernetes cluster enrolled in Teleport. See Enroll a Kubernetes cluster. This guide assumes it has the label
env: dev. - Permission to create roles and edit your own user, for example with the
editorrole. kubectlaccess to the Kubernetes cluster as an administrator, to create a role binding.tsh,tctlandjq, and Node.js 20 or later fornpx.- An MCP client that can start a stdio command. The examples use Claude Code. On your dev computer, install it and sign in. Beams include Claude Code and Node.js, and Claude Code is already connected to the LLM gateway.
Install the client tools and sign in
Beams is a Teleport project and uses official Teleport client tools.
The client tools include tsh to sign in and run commands, and tctl to administer your cluster if you have permission.
Cluster: example.beams.run. Edit this example to use your cluster name.
Install version 18.11.10 of the client:
Download and open the macOS installer, then follow its instructions.
curl -O https://cdn.teleport.dev/teleport-tools-18.11.10.pkg
open teleport-tools-18.11.10.pkgFor Linux x86-64, download and install the client tools:
curl -O https://cdn.teleport.dev/teleport-v18.11.10-linux-amd64-bin.tar.gz
tar -xzf teleport-v18.11.10-linux-amd64-bin.tar.gz
sudo ./teleport/installFor Windows x86-64, run these commands in PowerShell. Add the extraction directory ($env:LOCALAPPDATA\Teleport) to your user PATH to use tsh in future terminals; the last command adds it to this terminal's PATH.
Invoke-WebRequest -Uri https://cdn.teleport.dev/teleport-v18.11.10-windows-amd64-bin.zip -OutFile teleport.zip
Expand-Archive -Path teleport.zip -DestinationPath "$env:LOCALAPPDATA\Teleport" -Force
$env:Path += ";$env:LOCALAPPDATA\Teleport"Follow the official client tools install guide for other versions and architectures.
Check that you’re running v18.11.10 of the client with tsh version.
tsh versionI sign in without a password (e.g. a passkey).
tsh login --proxy='example.beams.run' --auth=passwordlessI have a password & MFA set up for my account:
Replace you@example.com with your Teleport username.
tsh login --proxy='example.beams.run' --user=you@example.comI sign in with SSO (e.g. Okta, GitHub, SAML).
tsh login --proxy='example.beams.run'1. Create a read-only role
-
In the Kubernetes cluster, bind a group to the built-in
viewClusterRole.viewcan read most resources but not Secrets. Save this asbeams-agent-view.yaml:apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: beams-agent-view subjects: - kind: Group name: beams-agent-view apiGroup: rbac.authorization.k8s.io roleRef: kind: ClusterRole name: view apiGroup: rbac.authorization.k8s.iokubectl apply -f beams-agent-view.yaml -
In Teleport, create a role that reaches clusters labelled
env: devas that group, with read verbs only. Save it askube-agent-readonly.yaml:kind: role version: v8 metadata: name: kube-agent-readonly spec: allow: kubernetes_labels: env: dev kubernetes_groups: - beams-agent-view kubernetes_resources: # Namespaced resources, such as pods and deployments - kind: '*' api_group: '*' namespace: '*' name: '*' verbs: [get, list, watch] # Cluster-wide resources, such as namespaces and nodes - kind: '*' api_group: '*' namespace: '' name: '*' verbs: [get, list, watch]Change
kubernetes_labelsto match your cluster’s labels. To limit the agent to some namespaces, list them innamespace. See Kubernetes access controls. -
Create the role and add it to your user while keeping your existing roles. You can delegate only roles that you hold:
tctl create -f kube-agent-readonly.yaml me=$(tsh status --format=json | jq -r .active.username) roles=$(tctl get "users/$me" --format=json | jq -r '.[0].spec.roles | join(",")') tctl users update "$me" --set-roles="$roles,kube-agent-readonly" -
Log in again, so that your session includes the new role.
2. Configure the MCP server
kubernetes-mcp-server reads its settings from a TOML file. Create kube-mcp.toml in your project directory. Read-only mode hides the tools that create, change or delete resources:
read_only = true
toolsets = ["core"]The core toolset lists and reads pods, events, namespaces, nodes and other resources, and reads pod logs. To add Helm tools, add "helm" to toolsets. See the configuration reference.
The examples pin the server version. Newer versions may change configuration options or tools.
3. Connect from your dev computer
-
List the clusters you can reach, and log in to one. Replace
my-clusterwith its name:tsh kube ls tsh kube login my-clustertsh kube loginupdates your default kubeconfig, which the MCP server reads. The kubeconfig usestshto get short-lived certificates. -
In the project directory with
kube-mcp.toml, add the MCP server to the project’s Claude Code configuration:claude mcp add kubernetes -s project -- npx -y kubernetes-mcp-server@0.1.3 --config "$PWD/kube-mcp.toml"For other clients, add the same command to the client’s MCP configuration. For example, in Cursor’s
mcp.json:{ "mcpServers": { "kubernetes": { "command": "npx", "args": ["-y", "kubernetes-mcp-server@0.1.3", "--config", "/path/to/kube-mcp.toml"] } } }In VS Code, run
code --add-mcpwith the same command, name and arguments. -
Start Claude Code in the project directory and approve the
kubernetesserver when it asks. Then check that it’s connected:claude mcp list -
Ask Claude Code:
Using the kubernetes MCP tools, list the namespaces and the pods in the default namespace, then delete one of the pods.It lists the namespaces and pods but has no tool to delete them. Even without read-only mode, Teleport rejects the delete with
403 Forbidden, because the role allows onlyget,listandwatch.
4. Connect from inside a beam
An agent beam reaches the cluster with the roles you delegate, not your own. Inside a beam, tsh is already signed in as the beam identity. tsh kube login doesn’t work in a beam. Use tsh proxy kube --exec instead, which starts a local proxy and runs a command with KUBECONFIG pointing at it.
-
Start the agent beam with only the read-only role, and open its shell:
tsh beams add --roles=kube-agent-readonly -
Inside the beam, check that the cluster is listed, then create the MCP server configuration and add the server to Claude Code:
tsh kube ls printf 'read_only = true\ntoolsets = ["core"]\n' > kube-mcp.toml claude mcp add kubernetes -- npx -y kubernetes-mcp-server@0.1.3 --config "$PWD/kube-mcp.toml" -
Start Claude Code through the Kubernetes proxy, in a mode that skips permission prompts. Replace
my-clusterwith the cluster’s name. Teleport RBAC and Kubernetes RBAC still limit everything it does.tsh proxy kube my-cluster --exec --exec-cmd claude --exec-arg=--dangerously-skip-permissionsClaude Code and the MCP server it starts inherit
KUBECONFIGfrom the proxy. The proxy stops when you quit Claude Code. -
Enter the following prompt:
Using the kubernetes MCP tools, find any pods that are not running in the default namespace and show their recent events and logs. Then restart them.
The agent reads pods, events and logs but can’t restart anything:
- In read-only mode, the MCP server has no tools that change resources.
- If the agent calls the Kubernetes API another way, Teleport rejects anything other than
get,listandwatch. - Kubernetes RBAC denies reading Secrets, because the
viewClusterRole doesn’t include them.
The agent may then file a Just-in-Time access request for more access. Nothing changes unless a reviewer approves the request.
Teleport behind a TLS-terminating load balancer
If a load balancer or reverse proxy in front of Teleport terminates TLS, tsh kube login can’t reach the cluster directly. Use a local proxy on your dev computer too:
tsh proxy kube my-cluster --exec --exec-cmd claudeAlternatively, start a proxy on a fixed port with tsh proxy kube my-cluster -p 8888, and set kubeconfig in kube-mcp.toml to the kubeconfig path it prints. Teleport Connect can also run the proxy. Its terminal sets KUBECONFIG.
Clean up
-
On your dev computer, remove the MCP server from the project configuration:
claude mcp remove kubernetes -s project -
Delete the agent beam:
tsh beams ls tsh beams rm <agent-beam> -
Remove the role from your user, then delete it:
me=$(tsh status --format=json | jq -r .active.username) roles=$(tctl get "users/$me" --format=json | jq -r '[.[0].spec.roles[] | select(. != "kube-agent-readonly")] | join(",")') tctl users update "$me" --set-roles="$roles" tctl rm roles/kube-agent-readonly -
Remove the Kubernetes role binding:
kubectl delete clusterrolebinding beams-agent-view
Troubleshoot
- The cluster doesn’t appear in
tsh kube ls. Your roles don’t match its labels. Checkkubernetes_labelsagainst the labelstsh kube lsshows to an administrator. 403 Forbiddenfor every request. The Teleport role allows the request, but the Kubernetes group has no permissions. Check the role binding withkubectl get clusterrolebinding beams-agent-view -o yaml.- The MCP server fails with “unknown flag”. Recent versions of
kubernetes-mcp-serverread settings such asread_onlyandkubeconfigfrom the TOML file, not from flags. - Tool calls fail after a while. The
tshsession expired. Runtsh loginon your dev computer, then retry the call. In a beam, restarttsh proxy kube.