Kubernetes Manager MCP server

Manage Kubernetes cluster resources and deployments.
Back to servers
Setup instructions
Provider
Flux159
Release date
Dec 08, 2024
Language
TypeScript
Stats
833 stars

The MCP Server Kubernetes provides an interface to manage Kubernetes clusters through the Model Context Protocol. It enables AI assistants like Claude to interact with your Kubernetes infrastructure directly.

Installation

Prerequisites

Before using the MCP Server Kubernetes, ensure you have:

  1. kubectl installed and available in your PATH
  2. A valid kubeconfig file with contexts configured
  3. Access to a Kubernetes cluster configured for kubectl
  4. Helm v3 installed (optional, only required for Helm operations)

Using with Claude Desktop

To set up the MCP Server Kubernetes with Claude Desktop, add the server configuration to your Claude Desktop configuration file:

{
  "mcpServers": {
    "kubernetes": {
      "command": "npx",
      "args": ["mcp-server-kubernetes"]
    }
  }
}

By default, the server loads kubeconfig from ~/.kube/config.

Using with mcp-chat

You can also use the MCP Server Kubernetes with mcp-chat, a CLI chat client for MCP servers:

npx mcp-chat --server "npx mcp-server-kubernetes"

Alternatively, use your existing Claude Desktop configuration:

For Mac:

npx mcp-chat --config "~/Library/Application Support/Claude/claude_desktop_config.json"

For Windows:

npx mcp-chat --config "%APPDATA%\Claude\claude_desktop_config.json"

Usage

Basic Kubernetes Operations

The MCP Server supports the following kubectl operations:

  • View Resources:

    • Get or list resources with kubectl_get
    • Describe resources with kubectl_describe
    • Get logs with kubectl_logs
  • Manage Resources:

    • Create resources with kubectl_create
    • Apply YAML manifests with kubectl_apply
    • Delete resources with kubectl_delete
    • Scale resources with kubectl_scale
    • Update resources with kubectl_patch
    • Manage deployment rollouts with kubectl_rollout
  • Information and Utilities:

    • Manage kubectl contexts with kubectl_context
    • Explain Kubernetes resources with explain_resource
    • List API resources with list_api_resources
    • Execute any kubectl command with kubectl_generic
    • Test connection with ping

Advanced Operations

  • Port Forwarding:

    • Forward ports to pods and services with port_forward
    • Stop port forwarding with stop_port_forward
  • Helm Operations:

    • Install charts with install_helm_chart
    • Upgrade charts with upgrade_helm_chart
    • Uninstall charts with uninstall_helm_chart

Troubleshooting

The server includes a specialized k8s-diagnose prompt that provides systematic troubleshooting for Kubernetes pods:

  • It accepts a keyword to identify relevant pods
  • An optional namespace parameter narrows the search
  • The prompt guides you through identifying issues, collecting evidence, and suggesting remediation steps

Non-Destructive Mode

For safety, you can run the server in non-destructive mode that disables destructive operations:

ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS=true npx mcp-server-kubernetes

Configure this in Claude Desktop with:

{
  "mcpServers": {
    "kubernetes-readonly": {
      "command": "npx",
      "args": ["mcp-server-kubernetes"],
      "env": {
        "ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS": "true"
      }
    }
  }
}

In non-destructive mode, the following operations remain available:

  • Resource information: kubectl_get, kubectl_describe, kubectl_logs, etc.
  • Resource creation/modification: kubectl_apply, kubectl_create, kubectl_scale, etc.
  • Helm operations: install_helm_chart, upgrade_helm_chart
  • Connectivity: port_forward, stop_port_forward
  • Context management: kubectl_context

However, destructive operations like kubectl_delete, uninstall_helm_chart, and cleanup are disabled.

Verification

To verify your connection is working properly, ask Claude to list your pods or create a test deployment. If you encounter errors, open a terminal and run kubectl get pods to check if you can connect to your cluster without credential issues.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "kubernetes" '{"command":"npx","args":["mcp-server-kubernetes"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "kubernetes": {
            "command": "npx",
            "args": [
                "mcp-server-kubernetes"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "kubernetes": {
            "command": "npx",
            "args": [
                "mcp-server-kubernetes"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later