Kubernetes MCP Server Lab
Giving Claude full access to a local Kubernetes sandbox over MCP.
I wanted Claude to drive my local Kubernetes cluster. Not just look at it. Create things, change them and tear them down.
This lab gets you there in about 15 minutes. You’ll run a kind cluster on your Mac, give an MCP server a cluster-admin identity, and plug it into Claude Desktop. Then you’ll prove every verb works.
Why this server
There are a lot of Kubernetes MCP servers out there. None are official Kubernetes projects. I picked containers/kubernetes-mcp-server for three reasons:
- It talks to the API directly. It’s written in Go. It doesn’t wrap
kubectlorhelm. - The Kubernetes community uses it. SIG Apps’ MCP Lifecycle Operator uses it as its example server.
- It runs anywhere. You can run it with npx, uvx, a native binary or a container.
What you need
- A Mac with Docker running (Docker Desktop, OrbStack or similar)
- kind and
kubectl - Node.js, for
npx - Claude Desktop
Step 1: Create a cluster
If you already have a local cluster, skip this step.
kind create cluster --name mcp-lab
kubectl get nodes
You should see one node in the Ready state.
Step 2: Create a ServiceAccount with full access
You could point the server at your own kubeconfig. I prefer a dedicated identity. It keeps the server off any other contexts you have, and you can revoke it in one command.
This is a sandbox, so we bind it to cluster-admin. Don’t do this on a shared or production cluster.
kubectl create namespace mcp
kubectl create serviceaccount mcp-admin -n mcp
kubectl create clusterrolebinding mcp-admin-crb \
--clusterrole=cluster-admin \
--serviceaccount=mcp:mcp-admin
Step 3: Mint a token
A kubectl create token token expires. For a lab, I want one that lasts. A Secret of type service-account-token never expires:
kubectl apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: mcp-admin-token
namespace: mcp
annotations:
kubernetes.io/service-account.name: mcp-admin
type: kubernetes.io/service-account-token
EOF
TOKEN="$(kubectl get secret mcp-admin-token -n mcp \
-o jsonpath='{.data.token}' | base64 -d)"
Step 4: Build a kubeconfig for the server
This file holds one cluster, one user and one context. That’s all the server will ever see.
API_SERVER="$(kubectl config view --minify \
-o jsonpath='{.clusters[0].cluster.server}')"
CA_FILE="/tmp/k8s-ca-$$.crt"
kubectl config view --minify --raw \
-o jsonpath='{.clusters[0].cluster.certificate-authority-data}' \
| base64 -d > "$CA_FILE"
KUBECONFIG_FILE="$HOME/.kube/mcp-admin.kubeconfig"
kubectl config --kubeconfig="$KUBECONFIG_FILE" set-cluster mcp-cluster \
--server="$API_SERVER" --certificate-authority="$CA_FILE" --embed-certs=true
kubectl config --kubeconfig="$KUBECONFIG_FILE" set-credentials mcp-admin \
--token="$TOKEN"
kubectl config --kubeconfig="$KUBECONFIG_FILE" set-context mcp-admin-context \
--cluster=mcp-cluster --user=mcp-admin
kubectl config --kubeconfig="$KUBECONFIG_FILE" use-context mcp-admin-context
chmod 600 "$KUBECONFIG_FILE"
rm -f "$CA_FILE"
Check it before you go further:
export KC=~/.kube/mcp-admin.kubeconfig
kubectl --kubeconfig=$KC auth whoami
kubectl --kubeconfig=$KC auth can-i '*' '*' --all-namespaces
whoami should show system:serviceaccount:mcp:mcp-admin. can-i should print yes.
Step 5: Add the server to Claude Desktop
Open ~/Library/Application Support/Claude/claude_desktop_config.json. Add a kubernetes entry under mcpServers. Keep any servers you already have.
{
"mcpServers": {
"kubernetes": {
"command": "npx",
"args": ["-y", "kubernetes-mcp-server@latest"],
"env": {
"KUBECONFIG": "/Users/YOUR_USER/.kube/mcp-admin.kubeconfig"
}
}
}
}
Note what’s missing: --read-only. Leave that flag off and the server gets its full toolset.
Quit Claude Desktop all the way and reopen it.
If the server fails to start: GUI apps on macOS don’t get your shell’s PATH. Run which npx and put the full path in "command". The log lives at ~/Library/Logs/Claude/mcp-server-kubernetes.log.
Step 6: Prove it works
Open a new chat. Run these prompts in order. Claude asks you to approve each tool call.
| # | Prompt | What it tests |
|---|---|---|
| 1 | List all namespaces in my cluster. | Read |
| 2 | Show me the pods in kube-system. | Read |
| 3 | Create a namespace called mcp-test and deploy nginx with 1 replica into it. |
Create |
| 4 | Scale the nginx deployment in mcp-test to 3 replicas. |
Update |
| 5 | Run nginx -v inside one of the nginx pods. |
Exec |
| 6 | Delete the mcp-test namespace. |
Delete |
Don’t trust the chat alone. Check each change from your terminal:
kubectl get all -n mcp-test -o wide
kubectl get ns mcp-test # after step 6: NotFound
What I saw
My cluster has five nodes. Here’s how each step went:
- Read: Claude listed my namespaces, including the new
mcpone. It found 16 healthy pods inkube-system. - Create: The server applied a Namespace and a Deployment with server-side apply. The pod was running in about 25 seconds.
- Update: The scheduler put the three replicas on three different workers.
- Exec:
nginx -vreturnednginx/1.30.8. - Delete: The namespace and everything in it disappeared.
One detail I liked: the Deployment’s managedFields lists kubernetes-mcp-server as the field manager. You can always tell what the AI changed.
kubectl get deploy nginx -n mcp-test \
-o jsonpath='{.metadata.managedFields[*].manager}'
Tuning
- Toolsets. The defaults are
core,configandhelm. Add more with--toolsets, for example"--toolsets", "core,config,helm,tekton". Others includekubevirt,kialiand a set of observability tools. - Guardrails.
--read-onlyblocks every write.--disable-destructivesits in the middle: it allows changes but blocks deletes. - TOML config. Pass a file with
--config. You can deny whole kinds, such asSecret, with[[denied_resources]].
Clean up
Remove the identity:
kubectl delete clusterrolebinding mcp-admin-crb
kubectl delete namespace mcp
rm ~/.kube/mcp-admin.kubeconfig
Or remove the whole lab:
kind delete cluster --name mcp-lab
Then delete the kubernetes block from your Claude Desktop config.
Wrap up
Setup took six steps, and Claude can now run anything in the cluster that you can run with kubectl. On a sandbox, that’s what I want. On anything else, I’d start with --read-only.