首页/☁️云平台/mcp-kubernetes-server

mcp-kubernetes-server

查看源码
2025-5-5
Words 845Read Time 3 min
Score:85

MCP Kubernetes服务器,连接AI助手与Kubernetes集群,实现自然语言指令到Kubernetes操作的转换。

mcp-kubernetes-server

mcp-kubernetes-server 是一个基于模型上下文协议(Model Context Protocol, MCP)的服务器,旨在为 AI 助手提供与 Kubernetes 集群交互的能力。它充当 AI 工具(如 Claude、Cursor 和 GitHub Copilot)与 Kubernetes 之间的桥梁,将自然语言请求转换为 Kubernetes 操作,并以 AI 工具可以理解的格式返回结果。
通过 mcp-kubernetes-server,AI 工具可以:
  • 查询 Kubernetes 资源
  • 执行 kubectl 命令
  • 通过自然语言交互管理 Kubernetes 集群
  • 诊断和解释 Kubernetes 资源的状态

工作原理

notion image

安装指南

Docker

获取 Kubernetes 集群的 kubeconfig 文件,并在 mcpServers 中配置(将 src 路径替换为你的 kubeconfig 路径):

UVX

如果尚未安装 uv,请先安装并将其添加到 PATH 中,例如使用 curl:
如果尚未安装 kubectl,请先安装并将其添加到 PATH 中,例如:
如果尚未安装 helm,请先安装并将其添加到 PATH 中,例如:
Claude DesktopCursorChatGPT CopilotGithub Copilot 或其他支持的 AI 客户端中配置 MCP 服务器,例如:

MCP 服务器选项

环境变量:
  • KUBECONFIG: kubeconfig 文件的路径,例如 /home/<username>/.kube/config
命令行参数:

使用方法

在 AI 客户端中提出关于 Kubernetes 集群的任何问题,例如:

可用工具

mcp-kubernetes-server 提供了一组全面的工具,用于与 Kubernetes 集群交互,按操作类型分类:

命令工具

这些工具提供通用的命令执行能力:
工具
描述
参数
kubectl
运行任何 kubectl 命令并返回输出
command (字符串)
helm
运行任何 helm 命令并返回输出
command (字符串)

读取工具

这些工具提供对 Kubernetes 资源的只读访问:
工具
描述
参数
k8s_get
获取任何 Kubernetes 对象(或列表)作为 JSON 字符串
resource (字符串), name (字符串), namespace (字符串)
k8s_describe
显示特定资源或资源组的详细信息
resource_type (字符串), name (字符串, 可选), namespace (字符串, 可选), selector (字符串, 可选), all_namespaces (布尔值, 可选)
k8s_logs
打印 pod 中容器的日志
pod_name (字符串), container (字符串, 可选), namespace (字符串, 可选), tail (整数, 可选), previous (布尔值, 可选), since (字符串, 可选), timestamps (布尔值, 可选), follow (布尔值, 可选)
k8s_events
列出集群中的事件
namespace (字符串, 可选), all_namespaces (布尔值, 可选), field_selector (字符串, 可选), resource_type (字符串, 可选), resource_name (字符串, 可选), sort_by (字符串, 可选), watch (布尔值, 可选)
k8s_apis
列出 Kubernetes 集群中所有可用的 API
k8s_crds
列出 Kubernetes 集群中所有自定义资源定义(CRDs)
k8s_top_nodes
显示节点的资源使用情况(CPU/内存)
sort_by (字符串, 可选)
k8s_top_pods
显示 pod 的资源使用情况(CPU/内存)
namespace (字符串, 可选), all_namespaces (布尔值, 可选), sort_by (字符串, 可选), selector (字符串, 可选)
k8s_rollout_status
获取部署、守护进程集或状态集的 rollout 状态
resource_type (字符串), name (字符串), namespace (字符串, 可选)
k8s_rollout_history
获取部署、守护进程集或状态集的 rollout 历史记录
resource_type (字符串), name (字符串), namespace (字符串, 可选), revision (字符串, 可选)
k8s_auth_can_i
检查是否允许执行某个操作
verb (字符串), resource (字符串), subresource (字符串, 可选), namespace (字符串, 可选), name (字符串, 可选)
k8s_auth_whoami
显示当前认证的用户主体

写入工具

这些工具提供对 Kubernetes 资源的创建、更新或修补操作:
工具
描述
参数
k8s_create
从 YAML/JSON 内容创建 Kubernetes 资源
yaml_content (字符串), namespace (字符串, 可选)
k8s_apply
通过文件名或 stdin 应用配置到资源
yaml_content (字符串), namespace (字符串, 可选)
k8s_expose
将资源暴露为新的 Kubernetes 服务
resource_type (字符串), name (字符串), port (整数), target_port (整数, 可选), namespace (字符串, 可选), protocol (字符串, 可选), service_name (字符串, 可选), labels (对象, 可选), selector (字符串, 可选), type (字符串, 可选)
k8s_run
在 pod 中创建并运行特定镜像
name (字符串), image (字符串), namespace (字符串, 可选), command (数组, 可选), env (对象, 可选), labels (对象, 可选), restart (字符串, 可选)
k8s_set_resources
为容器设置资源限制和请求
resource_type (字符串), resource_name (字符串), namespace (字符串, 可选), containers (数组, 可选), limits (对象, 可选), requests (对象, 可选)
k8s_set_image
为容器设置镜像
resource_type (字符串), resource_name (字符串), container (字符串), image (字符串), namespace (字符串, 可选)
k8s_set_env
为容器设置环境变量
resource_type (字符串), resource_name (字符串), container (字符串), env_dict (对象), namespace (字符串, 可选)
k8s_rollout_undo
撤销部署、守护进程集或状态集的 rollout
resource_type (字符串), name (字符串), namespace (字符串, 可选), to_revision (字符串, 可选)
k8s_rollout_restart
重启部署、守护进程集或状态集的 rollout
resource_type (字符串), name (字符串), namespace (字符串, 可选)
k8s_rollout_pause
暂停部署、守护进程集或状态集的 rollout
resource_type (字符串), name (字符串), `namespace》 (字符串, 可选)
k8s_rollout_resume
恢复部署、守护进程集或状态集的 rollout
resource_type (字符串), name (字符串), namespace (字符串, 可选)
k8s_scale
扩展资源
resource_type (字符串), name》 (字符串), replicas(整数),namespace` (字符串, 可选)
k8s_autoscale
自动扩展部署、副本集、状态集或复制控制器
resource_type (字符串), name (字符串), min (整数), max》 (整数), namespace(字符串, 可选),cpu_percent` (整数, 可选)
k8s_cordon
将节点标记为不可调度
node_name (字符串)
k8s_uncordon
将节点标记为可调度
node_name (字符串)
k8s_drain
为维护准备而排空节点
node_name (字符串), force (布尔值, 可选), ignore_daemonsets》 (布尔值, 可选), delete_local_data(布尔值, 可选),timeout` (整数, 可选)
k8s_taint
更新一个或多个节点的污点
node_name (字符串), key (字符串), value (字符串, 可选), effect (字符串)
k8s_untaint
移除节点的污点
node_name (字符串), key (字符串), effect (字符串, 可选)
k8s_exec_command
在容器中执行命令
pod_name (字符串), command (字符串), container (字符串, 可选), namespace (字符串, 可选), stdin (布尔值, 可选), tty (布尔值, 可选), timeout (整数, 可选)
k8s_port_forward
将一个或多个本地端口转发到 pod
resource_type (字符串), name (字符串), ports (数组), namespace (字符串, 可选), address (字符串, 可选)
k8s_cp
在容器之间复制文件和目录
src_path (字符串), dst_path (字符串), container (字符串, 可选), namespace (字符串, 可选)
k8s_patch
更新资源的字段
resource_type (字符串), name (字符串), patch (对象), namespace (字符串, 可选)
k8s_label
更新资源的标签
resource_type (字符串), name (字符串), labels (对象), namespace (字符串, 可选), overwrite (布尔值, 可选)
k8s_annotate
更新资源的注解
resource_type》 (字符串), name(字符串),annotations(对象),namespace(字符串, 可选),overwrite` (布尔值, 可选)

删除工具

这些工具提供对 Kubernetes 资源的删除操作:
工具
描述
参数
k8s_delete
按名称、标签选择器或命名空间中的所有资源删除资源
resource_type (字符串), name (字符串, 可选), namespace (字符串, 可选), label_selector (字符串, 可选), all_namespaces (布尔值, 可选), force》 (布尔值, 可选), grace_period` (整数, 可选)

开发指南

如何在本地运行项目:
如何检查 MCP 服务器的请求和响应:

贡献指南

该项目在 GitHub 上开源,地址为 feiskyer/mcp-kubernetes-server,采用 Apache License。
如果你想为项目做出贡献,请遵循以下步骤:
  1. Fork 仓库并克隆到本地。
  1. 为你的更改创建一个新分支。
  1. 进行更改并使用描述性的提交信息提交。
  1. 将更改推送到你的 Fork 仓库。
  1. 向主仓库提交 Pull Request。

许可证

该项目采用 Apache License 2.0 许可证。详情请参阅 LICENSE 文件。
上一篇
BurpSuite-MCP-Server
下一篇
clickhouse-mcp