MCP HubMCP Hub
Flux159

mcp-server-kubernetes

by: Flux159

MCP Server for kubernetes management commands

200created 08/12/2024
Visit
kubernetes
management

📌Overview

Purpose: The MCP Server Kubernetes is designed to connect and manage a Kubernetes cluster seamlessly.

Overview: This framework serves as an interface to facilitate interactions with Kubernetes clusters. By leveraging standard tools like kubectl and Helm, it enables users to perform a variety of cluster management tasks through a simple command-line interface.

Key Features:

  • Kubernetes Cluster Connectivity: Automatically connects to the current kubectl context for streamlined operations.

  • Resource Management: Allows users to list, create, delete, and describe various Kubernetes resources, including pods, services, deployments, and namespaces.

  • Helm Support: Integrates Helm v3 for managing chart installations, upgrades, and custom configurations within the Kubernetes environment.

  • Real-time Log Access: Supports fetching logs from pods for troubleshooting and includes features to observe Kubernetes events.

  • Port Forwarding: Facilitates port forwarding to specific pods or services, enhancing accessibility for user applications.


MCP Server Kubernetes

MCP Server that can connect to a Kubernetes cluster and manage it.

Usage with Claude Desktop

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

Prerequisites

  • Ensure that kubectl is installed and in your PATH.
  • A valid kubeconfig file with contexts configured.
  • Access to a Kubernetes cluster configured for kubectl (e.g., minikube, Rancher Desktop, GKE, etc.).
  • Helm v3 installed and in your PATH (optional).

Verify your connection by asking Claude to list your pods or create a test deployment. If you encounter errors, run kubectl get pods in your terminal to check for connectivity issues.

Usage with mcp-chat

mcp-chat is a CLI chat client for MCP servers that allows interaction with the Kubernetes server.

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

Alternatively, use your existing Claude Desktop configuration file:

Mac

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

Windows

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

Features

  • Connect to a Kubernetes cluster
  • List pods, services, deployments, nodes, and namespaces
  • Create and delete pods and namespaces
  • Get logs from pods
  • Support for Helm v3 (install, upgrade, uninstall charts)
  • kubectl explain and api-resources support
  • Get Kubernetes events
  • Port forwarding to pods or services

Local Development

git clone https://github.com/Flux159/mcp-server-kubernetes.git
cd mcp-server-kubernetes
bun install

Development Workflow

  1. Start the server in development mode:

    bun run dev
    
  2. Run unit tests:

    bun run test
    
  3. Build the project:

    bun run build
    
  4. Local testing with Inspector:

    npx @modelcontextprotocol/inspector node dist/index.js
    
  5. Local testing with Claude Desktop setup:

    {
      "mcpServers": {
        "mcp-server-kubernetes": {
          "command": "node",
          "args": ["/path/to/your/mcp-server-kubernetes/dist/index.js"]
        }
      }
    }
    
  6. Local testing with mcp-chat:

    npm run chat
    

Contributing

See the CONTRIBUTING.md file for details.

Advanced

For more advanced topics, see the ADVANCED_README.md.

Architecture

This section describes the high-level architecture of the MCP Kubernetes server.

Request Flow

A sequence diagram illustrates how requests flow through the system:

  1. Client sends a request via STDIO.
  2. The server routes the request to either a tools handler or a resource handler.
  3. The handler interacts with the Kubernetes API to process the request.
  4. The final response is sent back to the client.

Publishing a New Release

Go to the releases page, draft a new release, choose a tag with the format "v{major}.{minor}.{patch}", and publish the release. This will trigger a new build and publish the release to npm automatically.

Not Planned

No plans for authentication or adding clusters to kubectx.