mc

mcp-k8s

MCP-K8S is an AI-driven Kubernetes resource management tool that allows users to operate any resources in Kubernetes clusters through natural language interaction, including native resources (like Deployment, Service) and custom resources (CRD). No need to memorize complex commands - just describe your needs, and AI will accurately execute the corresponding cluster operations, greatly enhancing the usability of Kubernetes.

Publishermcp-k8s
Submitted date4/13/2025

Unleashing LLMs on Kubernetes: mcp-k8s - A Model Context Protocol Server for Seamless Cluster Interaction

mcp-k8s bridges the gap between Large Language Models (LLMs) and Kubernetes clusters, enabling intuitive and powerful management through natural language. This open-source project provides a robust and secure Model Control Protocol (MCP) server, empowering users to interact with their Kubernetes infrastructure in a revolutionary way.

Key Capabilities

  • Kubernetes Resource Discovery: Intelligently identifies and exposes all available Kubernetes resource types, including built-in resources and Custom Resource Definitions (CRDs).
  • Comprehensive CRUD Operations: Facilitates Create, Read, Update, and Delete (CRUD) operations on Kubernetes resources, all driven by natural language commands.
  • Granular Access Control: Offers configurable write operation controls, allowing administrators to independently enable or disable create, update, and delete functionalities for enhanced security.
  • Secure Cluster Connectivity: Establishes secure connections to Kubernetes clusters using standard kubeconfig files, adhering to established security best practices.

Transformative Use Cases

1. LLM-Powered Kubernetes Resource Management

  • Natural Language Interaction: Manage Kubernetes resources using intuitive natural language commands, eliminating the need for complex kubectl syntax.
  • Complex Batch Operations: Define intricate batch operations in natural language, leveraging the LLM to translate them into precise resource manipulations.
  • Intelligent Resource Status Queries: Obtain real-time cluster resource status updates through natural language queries, receiving clear and concise responses.

2. Automating Kubernetes Operations

  • Intelligent Operations Assistant: Empower operators with an AI-driven assistant for daily cluster management tasks, streamlining workflows and improving efficiency.
  • AI-Assisted Problem Diagnosis: Expedite cluster problem diagnosis by describing issues in natural language, enabling the LLM to identify potential root causes and solutions.
  • Configuration Optimization: Leverage the LLM's understanding of Kubernetes best practices to review and optimize resource configurations, ensuring optimal performance and security.

3. Streamlining Development and Testing

  • Rapid Prototyping: Accelerate development cycles by quickly creating and validating resource configurations through natural language commands.
  • Simplified Environment Management: Streamline test environment resource management, enabling rapid creation, modification, and cleanup of test resources.
  • Automated Configuration Generation: Automatically generate resource configurations that adhere to best practices, based on high-level requirement descriptions.

4. Revolutionizing Kubernetes Education and Training

  • Interactive Learning Experience: Enable newcomers to learn Kubernetes concepts and operations through engaging natural language interactions.
  • Best Practice Guidance: Provide real-time best practice suggestions during resource operations, fostering a culture of excellence.
  • Contextual Error Explanation: Offer clear and concise explanations of errors, along with actionable correction suggestions, accelerating the learning process.

Architectural Deep Dive

1. Project Overview

mcp-k8s is a robust MCP server designed for seamless interaction with Kubernetes clusters. It leverages standard input/output (stdio) for communication and provides a comprehensive suite of tools for managing Kubernetes resources.

2. Technical Foundation

  • Go: The project is built using Go, ensuring performance, reliability, and maintainability.
  • mcp-go SDK: Utilizes the mcp-go SDK (https://github.com/mark3labs/mcp-go) for streamlined MCP server development.
  • Kubernetes client-go Library: Leverages the official Kubernetes client-go library for secure and reliable communication with Kubernetes clusters.
  • Stdio Communication: Employs standard input/output streams for efficient and platform-independent communication.

3. Core Components

  1. MCP Server: Implements an stdio-based MCP server using the server package from mcp-go.
  2. K8s Client: Establishes secure connections to Kubernetes clusters using the client-go library.
  3. Tool Implementations: Provides a rich set of MCP tools for performing various Kubernetes operations.

4. Available Tools

Resource Type Discovery

  • get_api_resources: Retrieves a comprehensive list of all supported API resource types within the cluster.

Resource Management

  • get_resource: Retrieves detailed information about a specific Kubernetes resource.
  • list_resources: Lists all instances of a particular resource type.
  • create_resource: Creates new Kubernetes resources (can be disabled).
  • update_resource: Updates existing Kubernetes resources (can be disabled).
  • delete_resource: Deletes Kubernetes resources (can be disabled).

Deployment and Usage

mcp-k8s supports two communication modes:

1. Stdio Mode (Default)

In stdio mode, mcp-k8s communicates with the client through standard input/output streams. This is the default mode and is suitable for most use cases.

# Run in stdio mode (default) { "mcpServers": { "mcp-k8s": { "command": "/path/to/mcp-k8s", "args": [ "-kubeconfig", "/path/to/kubeconfig", "-enable-create", "-enable-delete", "-enable-update", "-enable-list" ] } } }

2. SSE Mode

In SSE (Server-Sent Events) mode, mcp-k8s exposes an HTTP endpoint to mcp client. You can deploy the service on a remote server (but you need to pay attention to security).

# Run in SSE mode ./bin/mcp-k8s -kubeconfig=/path/to/kubeconfig -transport=sse -port=8080 -host=localhost -enable-create -enable-delete -enable-list -enable-update # This command will open all operations

mcp config

{ "mcpServers": { "mcp-k8s": { "url": "http://localhost:8080/sse", "args": [] } } }

SSE mode configuration:

  • -transport: Set to "sse" to enable SSE mode
  • -port: HTTP server port (default: 8080)
  • --host: HTTP server host (default: "localhost")

Getting Started

Direct Usage

Download pre-built binaries for your platform from the releases page for immediate use.

Building from Source

git clone https://github.com/silenceper/mcp-k8s.git cd mcp-k8s go build -o bin/mcp-k8s cmd/server/main.go

Command-Line Arguments

  • -kubeconfig: Path to Kubernetes configuration file (uses default config if not specified).
  • -enable-create: Enable resource creation operations (default: false).
  • -enable-update: Enable resource update operations (default: false).
  • -enable-delete: Enable resource deletion operations (default: false).
  • -enable-list: Enable resource list operations (default: true).
  • -transport: Transport type (stdio or sse) (default: "stdio").
  • -host: Host for SSE transport (default "localhost").
  • -port: TCP port for SSE transport (default 8080).

Integration with MCP Clients

mcp-k8s is an stdio-based MCP server that seamlessly integrates with any MCP-compatible LLM client. Refer to your MCP client's documentation for specific integration instructions.

Security Hardening

  • Granular Write Operation Control: Write operations are meticulously controlled through independent configuration switches, minimizing potential risks.
  • RBAC Enforcement: Employs Role-Based Access Control (RBAC) to ensure the K8s client operates with only the necessary permissions, adhering to the principle of least privilege.
  • Input Validation: Rigorously validates all user inputs to prevent injection attacks and ensure data integrity.

Stay Connected

Follow our WeChat Official Account for the latest updates and insights!

AI技术小林

Visit More

View All