/ Verzeichnis / Playground / k8s-mcp-server
● Community alexei-led ⚡ Sofort

k8s-mcp-server

von alexei-led · alexei-led/k8s-mcp-server

Give Claude kubectl, helm, istioctl, and argocd — with command validation, non-root execution, and scoped kubeconfig — so you can ops your cluster by chat.

k8s-mcp-server runs as a Docker container that mounts your kubeconfig read-only. It wraps kubectl/helm/istioctl/argocd plus Unix utilities (jq, grep, sed) for pipelines. Two security modes (default restrictive, permissive) and a command validator so Claude can't accidentally kubectl delete namespace your prod.

Warum nutzen

Hauptfunktionen

Live-Demo

In der Praxis

k8s.replay ▶ bereit
0/0

Installieren

Wählen Sie Ihren Client

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "k8s": {
      "command": "uvx",
      "args": [
        "k8s-mcp-server"
      ],
      "_inferred": true
    }
  }
}

Öffne Claude Desktop → Settings → Developer → Edit Config. Nach dem Speichern neu starten.

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "k8s": {
      "command": "uvx",
      "args": [
        "k8s-mcp-server"
      ],
      "_inferred": true
    }
  }
}

Cursor nutzt das gleiche mcpServers-Schema wie Claude Desktop. Projektkonfiguration schlägt die globale.

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "k8s": {
      "command": "uvx",
      "args": [
        "k8s-mcp-server"
      ],
      "_inferred": true
    }
  }
}

Klicken Sie auf das MCP-Servers-Symbol in der Cline-Seitenleiste, dann "Edit Configuration".

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "k8s": {
      "command": "uvx",
      "args": [
        "k8s-mcp-server"
      ],
      "_inferred": true
    }
  }
}

Gleiche Struktur wie Claude Desktop. Windsurf neu starten zum Übernehmen.

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "k8s",
      "command": "uvx",
      "args": [
        "k8s-mcp-server"
      ]
    }
  ]
}

Continue nutzt ein Array von Serverobjekten statt einer Map.

~/.config/zed/settings.json
{
  "context_servers": {
    "k8s": {
      "command": {
        "path": "uvx",
        "args": [
          "k8s-mcp-server"
        ]
      }
    }
  }
}

In context_servers hinzufügen. Zed lädt beim Speichern neu.

claude mcp add k8s -- uvx k8s-mcp-server

Einzeiler. Prüfen mit claude mcp list. Entfernen mit claude mcp remove.

Anwendungsfälle

Praxisnahe Nutzung: k8s-mcp-server

Morning cluster health check via chat

👤 SRE, platform engineers ⏱ ~5 min intermediate

Wann einsetzen: Daily, before stand-up — anything red? Any pods crashlooping?

Voraussetzungen
  • kubeconfig on host — Usually ~/.kube/config
Ablauf
  1. Start the MCP container
    Start k8s-mcp-server via Docker mounting ~/.kube read-only.✓ Kopiert
    → Container up
  2. Run the checks
    Across all namespaces, list pods not in Running state, nodes not Ready, and recent (last 1h) events of type Warning.✓ Kopiert
    → Three-part health report
  3. Triage
    For each crashlooping pod, get last 50 log lines and propose most likely cause.✓ Kopiert
    → Log excerpts + diagnoses

Ergebnis: 5-minute daily cluster pulse check.

Fallstricke
  • Running kubectl get events cluster-wide floods context — Always filter by time and type

Debug a failed Helm release

👤 Devs shipping Helm charts ⏱ ~15 min intermediate

Wann einsetzen: helm upgrade failed and you want to know why without copying error messages back and forth.

Ablauf
  1. Get history
    helm history my-app -n production. What changed between v4 (working) and v5 (failed)?✓ Kopiert
    → Version diff
  2. Diff templates
    Render the template for v5 with current values and compare against v4. Highlight differences.✓ Kopiert
    → Diff of rendered manifests
  3. Roll back if needed
    Roll back to v4. Confirm all pods become Ready.✓ Kopiert
    → Rollback + health check

Ergebnis: Fast recovery with understanding, not just luck.

Fallstricke
  • Rolling back without capturing the failure first means you can't fix forward — Always save helm get all v5 to a file before rolling back
Kombinieren mit: filesystem

Audit Argo CD apps for drift

👤 GitOps practitioners ⏱ ~20 min advanced

Wann einsetzen: You suspect someone kubectl'd something into prod that Argo CD doesn't know about.

Ablauf
  1. List out-of-sync apps
    argocd app list --output json. Filter to apps where sync status isn't Synced.✓ Kopiert
    → Out-of-sync list
  2. Diff each
    For each drifted app, run argocd app diff and summarize what's different from Git.✓ Kopiert
    → Per-app diff summary

Ergebnis: Clear picture of manual drift to reconcile.

Kombinationen

Mit anderen MCPs für 10-fache Wirkung

k8s + github

When an app is broken in cluster, open GitHub issue with pod logs

If any pod in 'payments' namespace is crashlooping, fetch logs and open a GitHub issue with them attached.✓ Kopiert

Werkzeuge

Was dieses MCP bereitstellt

WerkzeugEingabenWann aufrufenKosten
kubectl command: str (full kubectl args) General cluster ops free
helm command: str Release management free
istioctl command: str Service mesh ops free
argocd command: str GitOps ops (requires argocd login in container) free

Kosten & Limits

Was der Betrieb kostet

API-Kontingent
None
Tokens pro Aufruf
kubectl get -o yaml can be huge; prefer -o json | jq to trim
Kosten in €
Free, MIT
Tipp
Always use -o wide or -o jsonpath=... to trim. kubectl get all is a token-bomb.

Sicherheit

Rechte, Secrets, Reichweite

Minimale Scopes: Kubeconfig scoped to a least-privilege ServiceAccount
Credential-Speicherung: Mount ~/.kube read-only into the container
Datenabfluss: Traffic to your cluster API server only
Niemals gewähren: cluster-admin ServiceAccount to the kubeconfig used by the MCP

Fehlerbehebung

Häufige Fehler und Lösungen

The connection to the server localhost:8080 was refused

kubeconfig not mounted or KUBECONFIG env var wrong in the container.

Prüfen: docker exec ... kubectl config view
Command blocked in restrictive mode

Either craft a narrower command, or explicitly opt into permissive mode for that session.

Timeout on long-running command

Raise K8S_MCP_TIMEOUT. For truly long ops, run async via a Job and poll.

Alternativen

k8s-mcp-server vs. andere

AlternativeWann stattdessenKompromiss
Direct kubectl via ssh-managerYou prefer running kubectl on a jump hostLess structured; no command validation
Kagent / AIOps SaaS MCPsYou want managed service rather than self-hostedCosts money; less control

Mehr

Ressourcen

📖 Offizielle README auf GitHub lesen

🐙 Offene Issues ansehen

🔍 Alle 400+ MCP-Server und Skills durchsuchen