MCP Kubernetes Server

by abhijeetka
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Allows management of Kubernetes clusters through kubectl commands, providing tools for creating and managing deployments, pods, services, namespaces, and other resources, as well as performing operations like scaling, port forwarding, and viewing logs and events.

MCP Kubernetes 服务器

这是 Kubernetes 的 MCP(模型上下文协议)服务器,通过与 LLM 交互来控制 Kubernetes 集群。

概述

此客户端允许您通过 MCP 工具执行常见的 Kubernetes 操作。它封装了kubectl命令,以提供一个简单的 Kubernetes 资源管理界面。模型上下文协议 (MCP) 支持语言模型与 Kubernetes 操作之间的无缝交互。

什么是 MCP?

模型上下文协议 (MCP) 是一个框架,使语言模型能够以结构化的方式与外部工具和服务进行交互。它提供:

  • 向语言模型公开功能的标准化方法
  • 操作上下文管理
  • 工具发现和文档
  • 模型和工具之间的类型安全交互

使用示例

  • 在生产命名空间中为我创建一个名为 nginx-app 且图像为 nginx:latest 的新部署,其中包含 3 个副本。
  • 在生产命名空间中将部署 nginx-app 更新为版本 1.19。
  • 将生产命名空间中的部署 nginx-app 扩展到 5 个副本。
  • 获取生产命名空间中的 pod。
  • 获取集群中的所有命名空间。
  • 获取集群中的所有节点。
  • 获取集群中的所有服务。
  • 获取集群中的所有部署。
  • 获取集群中的所有作业。
  • 获取集群中的所有 cronjobs。
  • 获取集群中的所有 statefulset。
  • 获取集群中的所有守护进程集。
  • 当前的情况是什么。
  • 列出所有上下文。
  • 切换到上下文。
  • 获取生产命名空间中 pod 的日志。
  • 获取生产命名空间中的事件。
  • 在生产命名空间中使用 key1=value1 注释 pod。
  • 从生产命名空间中的 pod 中删除注释 key1。
  • 在生产命名空间中为 pod 添加标签 key1=value1。
  • 从生产命名空间中的 pod 中删除标签 key1。
  • 在端口 80 上的生产命名空间中公开部署 nginx-app。
  • 将生产命名空间中的名称为 port-forward 的 pod、deployment、service 转发到本地端口 8080。
  • 删除生产命名空间中具有名称的 pod、部署、服务、作业、cronjob、statefulset 和 daemonset。

即将推出的功能

  • 创建集群角色。
  • 删除集群角色。
  • 创建集群角色绑定。
  • 删除集群角色绑定。
  • 创建命名空间。
  • 删除命名空间。
  • 创建服务帐户。
  • 删除服务帐户。
  • 创建角色。
  • 删除角色。
  • 创建角色绑定.a
  • 删除角色绑定。

LLM 整合

此 MCP 客户端旨在与大型语言模型 (LLM) 无缝协作。其函数使用@mcp.tool()修饰,使其能够通过模型上下文协议 (MCP) 框架供 LLM 访问。

LLM题目示例

LLM 可以使用自然语言与您的 Kubernetes 集群进行交互。以下是一些示例提示:

  • “在生产命名空间中创建一个具有 3 个副本的新 nginx 部署”
  • “将 nginx-app 部署扩展至 5 个副本”
  • “将 nginx-app 镜像更新至 1.19 版本”

LLM 将解释这些自然语言请求并使用正确的参数调用适当的 MCP 函数。

LLM 集成的优势

  1. 自然语言界面:使用对话语言管理 Kubernetes 资源
  2. 降低命令复杂性:无需记住确切的 kubectl 语法
  3. 错误预防:LLM 可以验证输入并提供有用的错误消息
  4. 上下文感知:LLM 可以跨多个操作维护上下文
  5. 结构化交互:MCP 确保 LLM 和工具之间的类型安全且有文档记录的交互

要求

  • 通过kubectl配置 Kubernetes 集群访问
  • Python 3.x
  • MCP 框架安装和配置

安全说明

将此客户端与 LLM 一起使用时,请确保:

  • 您的 Kubernetes 集群已设置适当的访问控制
  • MCP 服务器在安全环境中运行
  • API 访问经过适当的身份验证和授权

与 Claude Desktop 一起使用

{ "mcpServers": { "Kubernetes": { "command": "uv", "args": [ "--directory", "~/mcp/mcp-k8s-server", "run", "kubernetes.py" ] } } }

贡献

欢迎大家为 MCP Kubernetes 服务器做出贡献!如果您愿意贡献:

  1. 分叉存储库
  2. 为您的功能创建一个新分支( git checkout -b feature/amazing-feature
  3. 进行更改
  4. 根据需要编写或更新测试
  5. 提交您的更改( git commit -m 'Add some amazing feature'
  6. 推送到你的分支( git push origin feature/amazing-feature
  7. 打开拉取请求

对于重大更改,请先打开一个问题来讨论您想要更改的内容。

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 Kubernetes 服务器:

npx -y @smithery/cli install @abhijeetka/mcp-k8s-server --client claude
-
security - not tested
F
license - not found
-
quality - not tested

一个服务器,使 LLM 能够通过自然语言命令管理 Kubernetes 集群,包装 kubectl 操作以提供常见 Kubernetes 任务的简化界面。

  1. Overview
    1. What is MCP?
      1. Usage Examples
        1. Upcoming Features
          1. LLM Integration
            1. Example LLM Prompts
            2. Benefits of LLM Integration
          2. Requirements
            1. Security Note
              1. Usage with Claude Desktop
                1. Contributing
                  1. Installing via Smithery
                ID: pbdab997o7