Use Kubernetes MCP Server

Claude Code and Kubernetes MCP Server in the Playground

This recipe shows how to use Red Hat's Kubernetes MCP server with Claude Code to manage Kubernetes clusters running in playgrounds. However, the instructions should be applicable to most mainstream coding agents and IDEs (Codex, Cursor, VS Code etc.) and alternative Kubernetes MCP servers.

Motivation

This is the recommended setup since it makes things much more secure (compared to running the agent and the MCP server on your local machine). Running Claude Code and the Kubernetes MCP server inside the playground VM means neither the agent nor the MCP server can access your local filesystem or credentials. The agent talks to the in-cluster Kubernetes API server directly without any port forwarding.

Prerequisites

  • labctl installed and authenticated

Setting up the environment

  1. Start a Kubernetes playground and capture its ID:
PLAY_ID=$(labctl playground start k3s)

Substitute k3s with k8s-omni or the name of your own custom Kubernetes playground.

  1. SSH into the playground:
labctl ssh $PLAY_ID
  1. Install Claude Code and log in:
curl -fsSL https://claude.ai/install.sh | bash
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc

claude login
  1. Install the Kubernetes MCP server and register it with Claude Code:
Go Binary
npx (Node.js required)

Download the MCP server binary from GitHub:

VERSION=0.0.60

curl -sL https://github.com/containers/kubernetes-mcp-server/releases/download/v${VERSION}/kubernetes-mcp-server-linux-amd64 \
    -o ~/.local/bin/kubernetes-mcp-server

chmod +x ~/.local/bin/kubernetes-mcp-server

Register the MCP server in Claude Code (assumes ~/.local/bin is in your PATH):

claude mcp add k8s -- kubernetes-mcp-server \
    --kubeconfig $HOME/.kube/config

This method is simpler since it doesn't require downloading the MCP server binary, but it requires Node.js to be preinstalled in the playground (it relies on npx to run the MCP server):

claude mcp add k8s -- npx kubernetes-mcp-server@latest \
    --kubeconfig $HOME/.kube/config
  1. Test it:
claude --dangerously-skip-permissions -p 'list all pods in all namespaces'

Local Claude Code and Kubernetes MCP Server with a Remote Cluster

Motivation

If you prefer to keep Claude Code on your local machine, you can still point the Kubernetes MCP server at a cluster running in a remote playground using the labctl kube-proxy helper.

Prerequisites

  • labctl installed and authenticated
  • Claude Code installed locally

Setting up the environment

  1. Start a Kubernetes playground and capture its ID:
PLAY_ID=$(labctl playground start k3s)

Substitute k3s with k8s-omni or the name of your own custom Kubernetes playground.

  1. Start a kube-proxy to connect to the remote Kubernetes cluster from your local machine:
labctl kube-proxy $PLAY_ID

Keep this command running - it holds the tunnel open and prints the kubeconfig path you'll need in the next step.

  1. In a new terminal, register the MCP server in Claude Code using the kubeconfig path printed by labctl kube-proxy:
Go Binary
npx (Node.js required)

Download the MCP server binary for your platform from the releases page:

VERSION=0.0.60

curl -sL https://github.com/containers/kubernetes-mcp-server/releases/download/v${VERSION}/kubernetes-mcp-server-linux-amd64 \
    -o ~/.local/bin/kubernetes-mcp-server

chmod +x ~/.local/bin/kubernetes-mcp-server

Then register it with Claude Code (assuming ~/.local/bin is in your PATH):

claude mcp add k8s-$PLAY_ID -- kubernetes-mcp-server \
    --kubeconfig ~/.iximiuz/labctl/plays/$PLAY_ID-cplane-01-laborant/kubeconfig

This method doesn't require downloading the MCP server binary separately (it relies on npx - hence Node.js - to run the MCP server):

claude mcp add k8s-$PLAY_ID -- npx kubernetes-mcp-server@latest \
    --kubeconfig ~/.iximiuz/labctl/plays/$PLAY_ID-cplane-01-laborant/kubeconfig
  1. Test it:
claude --dangerously-skip-permissions -p 'list all pods in all namespaces'