Connect Claude Code to Kubernetes Safely with MCP + RBAC

Intermediate

Build a read-only Kubernetes MCP server, connect Claude Code to it, and prove the agent can investigate your cluster but cannot change it — no mutating tool exists, and the same credential is denied on a direct write.

Learning Objectives

1
Stand up a read-only Kubernetes MCP server and register it with Claude Code
2
Scope an MCP ServiceAccount to least-privilege, namespace-scoped read-only RBAC
3
Prove the agent cannot mutate the cluster: no mutating tool exists, and the same credential returns 403 on a direct write
4
Use Claude Code to investigate live pods, logs, and events without any write access
Step 1

Confirm your tools and cluster are ready

This lab connects an AI agent to a real cluster. Before wiring anything together, confirm each moving part is present so a later failure is unambiguous.

Commands to Run

kubectl version --client -o yaml | head -n 4
kubectl get nodes
node --version
claude --version

What This Does

You need a reachable cluster (kubectl get nodes returns Ready nodes), Node.js to run the MCP server, and the Claude Code CLI to consume it.

Verifying now means any problem later is about the code you write, not the environment.

Expected Outcome

kubectl shows a client version, 'kubectl get nodes' lists at least one Ready node, node prints v18 or newer, and claude prints its version.

Pro Tips

  • 1
    No cluster yet? 'kind create cluster' or 'minikube start' gives you a throwaway one.
  • 2
    This whole lab is safe to run against a local sandbox cluster — nothing here touches a cloud account.

Common Mistakes to Avoid

  • ⚠️Pointing at a production cluster. Use a local kind/minikube cluster for this lab.
Was this step helpful?

All Steps (0 / 10 completed)