Skip to content

Kubernetes clusters

Give an MCP client read-only access to a Kubernetes cluster through Teleport, from your dev computer or from inside a beam.

Build with agents
On this page

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 login points 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

  1. 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.
  2. Your MCP client starts kubernetes-mcp-server as a local stdio server. The server reads the kubeconfig that tsh writes, which sends every request to the Teleport proxy.
  3. 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 editor role.
  • kubectl access to the Kubernetes cluster as an administrator, to create a role binding.
  • tsh, tctl and jq, and Node.js 20 or later for npx.
  • 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:

Operating system
macOS

Download and open the macOS installer, then follow its instructions.

CLI
curl -O https://cdn.teleport.dev/teleport-tools-18.11.10.pkg
open teleport-tools-18.11.10.pkg
Linux

For Linux x86-64, download and install the client tools:

CLI
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/install
Windows

For 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.

PowerShell
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.

CLI
tsh version
Sign-in method
Passwordless

I sign in without a password (e.g. a passkey).

CLI
tsh login --proxy='example.beams.run' --auth=passwordless
Password & MFA

I have a password & MFA set up for my account:

Replace you@example.com with your Teleport username.

CLI
tsh login --proxy='example.beams.run' --user=you@example.com
SSO

I sign in with SSO (e.g. Okta, GitHub, SAML).

CLI
tsh login --proxy='example.beams.run'

1. Create a read-only role

  1. In the Kubernetes cluster, bind a group to the built-in view ClusterRole. view can read most resources but not Secrets. Save this as beams-agent-view.yaml:

    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.io
    CLI · Admin terminal
    kubectl apply -f beams-agent-view.yaml
  2. In Teleport, create a role that reaches clusters labelled env: dev as that group, with read verbs only. Save it as kube-agent-readonly.yaml:

    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_labels to match your cluster’s labels. To limit the agent to some namespaces, list them in namespace. See Kubernetes access controls.

  3. Create the role and add it to your user while keeping your existing roles. You can delegate only roles that you hold:

    CLI · Local terminal
    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"
  4. 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:

TOML
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

  1. List the clusters you can reach, and log in to one. Replace my-cluster with its name:

    CLI · Local terminal
    tsh kube ls
    tsh kube login my-cluster

    tsh kube login updates your default kubeconfig, which the MCP server reads. The kubeconfig uses tsh to get short-lived certificates.

  2. In the project directory with kube-mcp.toml, add the MCP server to the project’s Claude Code configuration:

    CLI · Local terminal
    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:

    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-mcp with the same command, name and arguments.

  3. Start Claude Code in the project directory and approve the kubernetes server when it asks. Then check that it’s connected:

    CLI · Local terminal
    claude mcp list
  4. Ask Claude Code:

    Text
    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 only get, list and watch.

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.

  1. Start the agent beam with only the read-only role, and open its shell:

    CLI · Local terminal
    tsh beams add --roles=kube-agent-readonly
  2. Inside the beam, check that the cluster is listed, then create the MCP server configuration and add the server to Claude Code:

    CLI · Inside the agent beam
    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"
  3. Start Claude Code through the Kubernetes proxy, in a mode that skips permission prompts. Replace my-cluster with the cluster’s name. Teleport RBAC and Kubernetes RBAC still limit everything it does.

    CLI · Inside the agent beam
    tsh proxy kube my-cluster --exec --exec-cmd claude --exec-arg=--dangerously-skip-permissions

    Claude Code and the MCP server it starts inherit KUBECONFIG from the proxy. The proxy stops when you quit Claude Code.

  4. Enter the following prompt:

    Text
    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, list and watch.
  • Kubernetes RBAC denies reading Secrets, because the view ClusterRole 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:

CLI · Local terminal
tsh proxy kube my-cluster --exec --exec-cmd claude

Alternatively, 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

  1. On your dev computer, remove the MCP server from the project configuration:

    CLI · Local terminal
    claude mcp remove kubernetes -s project
  2. Delete the agent beam:

    CLI · Local terminal
    tsh beams ls
    tsh beams rm <agent-beam>
  3. Remove the role from your user, then delete it:

    CLI · Local terminal
    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
  4. Remove the Kubernetes role binding:

    CLI · Admin terminal
    kubectl delete clusterrolebinding beams-agent-view

Troubleshoot

  • The cluster doesn’t appear in tsh kube ls. Your roles don’t match its labels. Check kubernetes_labels against the labels tsh kube ls shows to an administrator.
  • 403 Forbidden for every request. The Teleport role allows the request, but the Kubernetes group has no permissions. Check the role binding with kubectl get clusterrolebinding beams-agent-view -o yaml.
  • The MCP server fails with “unknown flag”. Recent versions of kubernetes-mcp-server read settings such as read_only and kubeconfig from the TOML file, not from flags.
  • Tool calls fail after a while. The tsh session expired. Run tsh login on your dev computer, then retry the call. In a beam, restart tsh proxy kube.

Search docs

Loading search and AI…

Skills

Install all available skills. All Beams and Teleport skills are hosted in our OSS Teleport repository.

npx skills add https://github.com/gravitational/teleport