Token导航 LogoToken导航TokenDH.com
MCP Kubernetes Server logo
开发工具stdio官方级别未说明来源级核验

MCP Kubernetes Server

MCP Server

A Model Context Protocol (MCP) server that enables AI assistants to interact with Kubernetes clusters. It serves as a bridge between AI tools (like Claude, Cursor, and GitHub Copilot) and Kubernetes, translating natural language requests into Kubernetes operations and returning the results in a format the AI tools can understand.

工具数

0

提示词数

0

GitHub Stars

18

资源数

0
Kubernetes管理PythonClaude自然语言处理ClaudeCursor

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

feiskyer

提供方

feiskyer

最后核验

2026/5/18 02:17

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

uv run -m src.mcp_kubernetes_server.main

详细介绍

mcp kubernetes服务器

mcp-kubernetes-server 是一个实现模型上下文协议(MCP)的服务器,使AI助手(如Claude、Cursor和GitHub Copilot)能够与Kubernetes集群交互。它充当桥梁,将来自这些助手的自然语言请求转换为Kubernetes操作并返回结果。

它允许AI助手:

  • 查询Kubernetes资源
  • 执行kubectl命令
  • 通过自然语言交互管理Kubernetes集群
  • 诊断和解释Kubernetes资源的状态

运作原理

mcp-kubernetes-server 充当AI助手(支持模型上下文协议)和Kubernetes集群之间的中介。它接收来自这些助手的自然语言请求,并将其翻译成 kubectl 命令或直接调用Kubernetes API,并针对目标集群执行它们。然后,服务器处理结果并返回结构化响应,通过AI助手实现与Kubernetes环境的无缝交互。

![](https://github.com/feiskyer/mcp-kubernetes-server/blob/main/assets/mcp-kubernetes-server.png?raw=true)

如何安装

先决条件

安装前 mcp-kubernetes-server,确保您拥有以下内容:

  • 一个工作的Kubernetes集群。
  • A. kubeconfig 文件已正确配置以访问Kubernetes集群(服务器需要此文件进行交互)。
  • kubectl 命令行工具已安装并位于系统的PATH中(服务器用于执行许多Kubernetes命令)。
  • helm 命令行工具已安装并位于系统的PATH中(由服务器用于Helm chart操作)。
  • Python>=3.11,如果你打算直接使用 uvx (没有Docker)。

码头工人

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

{
  "mcpServers": {
    "kubernetes": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "--mount", "type=bind,src=/home/username/.kube/config,dst=/home/mcp/.kube/config",
        "ghcr.io/feiskyer/mcp-kubernetes-server"
      ]
    }
  }
}

UVX

使用以下命令运行服务器 uvx (随附的工具 uvPython打包器),首先确保 uv 已安装:

Install uv

安装 紫外线 如果尚未安装,请将其添加到PATH中,例如使用curl:

# For Linux and MacOS
curl -LsSf https://astral.sh/uv/install.sh | sh

Install kubectl

安装 kubectl 如果尚未安装,请将其添加到PATH中,例如。

# For Linux
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

# For MacOS
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl"

Install helm

安装 如果尚未安装,请将其添加到PATH中,例如。

curl -sSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
{
  "mcpServers": {
    "kubernetes": {
      "command": "uvx",
      "args": [
        "mcp-kubernetes-server"
      ],
      "env": {
        "KUBECONFIG": ""
      }
    }
  }
}

MCP服务器选项

Environment Variables

环境变量:

  • KUBECONFIG:kubeconfig文件的路径,例如。 /home//.kube/config.

Command line arguments

命令行参数:

usage: main.py [-h] [--disable-kubectl] [--disable-helm] [--disable-write]
               [--disable-delete] [--transport {stdio,sse,streamable-http}]
               [--host HOST] [--port PORT]

MCP Kubernetes Server

options:
  -h, --help            show this help message and exit
  --disable-kubectl     Disable kubectl command execution
  --disable-helm        Disable helm command execution
  --disable-write       Disable write operations
  --disable-delete      Disable delete operations
  --transport {stdio,sse,streamable-http}
                        Transport mechanism to use (stdio or sse or streamable-http)
  --host HOST           Host to use for sse or streamable-http server
  --port PORT           Port to use for sse or streamable-http server

用法

一旦 mcp-kubernetes-server 在您的AI客户端中安装和配置(使用Docker或UVX的“如何安装”部分中提供的JSON片段),您可以通过自然语言开始与Kubernetes集群交互。例如,你可以问:

What is the status of my Kubernetes cluster?

What is wrong with my nginx pod?

验证服务器: 如果您正在运行服务器 stdio 运输(通用 uvx AI客户端通常将启动并管理服务器进程。对于 ssestreamable-http 传输时,服务器独立运行。您本可以手动启动它(例如。, uvx mcp-kubernetes-server --transport sse)并且应该在终端中看到输出,指示它正在运行(例如。, INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)).如果AI客户端无法连接,您还可以检查服务器终端中的任何错误消息。

可用工具

mcp kubernetes服务器提供了一套全面的与kubernetes集群交互的工具,按操作类型分类:

Command Tools

命令工具

这些工具提供一般命令执行功能:

工具说明参数
kubectl运行任何kubectl命令并返回输出command (字符串)
运行任何helm命令并返回输出command (字符串)

Read Tools

阅读工具

这些工具提供对Kubernetes资源的只读访问:

工具说明参数
k8s_get获取任何Kubernetes对象(或列表)作为JSON字符串resource (字符串), name (字符串), namespace (字符串)
k8s_describes显示特定资源或资源组的详细信息resource_type (字符串), name (字符串,可选), namespace (字符串,可选), selector (字符串,可选), all_namespaces (布尔值,可选)
k8s_logs打印pod中容器的日志pod_name (字符串), container (字符串,可选), namespace (字符串,可选), tail (整数,可选), previous (布尔值,可选), since (字符串,可选), timestamps (布尔值,可选), follow (布尔值,可选)
k8s_事件列出集群中的事件namespace (字符串,可选), all_namespaces (布尔值,可选), field_selector (字符串,可选), resource_type (字符串,可选), resource_name (字符串,可选), sort_by (字符串,可选), watch (布尔值,可选)
k8s_api列出Kubernetes集群中的所有可用API
k8s_crds列出Kubernetes集群中的所有自定义资源定义(CRD)
k8s_top_nodes显示节点的资源使用情况(CPU/内存)sort_by (字符串,可选)
k8s_top_pods显示Pod的资源使用情况(CPU/内存)namespace (字符串,可选), all_namespaces (布尔值,可选), sort_by (字符串,可选), selector (字符串,可选)
k8s_推出状态获取部署、守护进程启动或状态集的卷展状态resource_type (字符串), name (字符串), namespace (字符串,可选)
k8s_推出历史获取部署、守护进程启动或状态集的推出历史记录resource_type (字符串), name (字符串), namespace (字符串,可选), revision (字符串,可选)
k8s_auth_can_i检查是否允许某个操作verb (字符串), resource (字符串), subresource (字符串,可选), namespace (字符串,可选), name (字符串,可选)
k8s_auth_woami显示您当前身份验证为none的主题

Write Tools

写入工具

这些工具为Kubernetes资源提供创建、更新或补丁操作:

工具说明参数
k8s_create从YAML/JSON内容创建Kubernetes资源yaml_content (字符串), namespace (字符串,可选)
k8s_apply按文件名或stdin将配置应用于资源yaml_content (字符串), namespace (字符串,可选)
k8s_曝光将资源作为新的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_推出\_ ndo撤消部署、守护进程启动或状态集的卷展栏resource_type (字符串), name (字符串), namespace (字符串,可选), to_revision (字符串,可选)
k8s_rollout_restart重新启动部署、守护进程启动或状态集的卷展栏resource_type (字符串), name (字符串), namespace (字符串,可选)
k8s_推出_使用暂停部署、守护进程启动或状态集的推出resource_type (字符串), name (字符串), namespace (字符串,可选)
k8s_推出_总结恢复部署、守护进程启动或状态集的推出resource_type (字符串), name (字符串), namespace (字符串,可选)
k8s_刻度扩展资源resource_type (字符串), name (字符串), replicas (整数), namespace (字符串,可选)
k8s_自动缩放自动缩放部署、副本集、有状态集或复制控制器resource_type (字符串), name (字符串), min (整数), max (整数), namespace (字符串,可选), cpu_percent (整数,可选)
k8s_警戒线将节点标记为不可调度node_name (字符串)
k8s_解锁将节点标记为可调度node_name (字符串)
k8s_排水管排空节点,为维护做准备node_name (字符串), force (布尔值,可选), ignore_daemonsets (布尔值,可选), delete_local_data (布尔值,可选), timeout (整数,可选)
k8s_污染更新一个或多个节点上的污染node_name (字符串), key (字符串), value (字符串,可选), effect (字符串)
k8s_取消打印从节点中删除污点node_name (字符串), key (字符串), effect (字符串,可选)
k8s_exec_命令在容器中执行命令pod_name (字符串), command (字符串), container (字符串,可选), namespace (字符串,可选), stdin (布尔值,可选), tty (布尔值,可选), timeout (整数,可选)
k8s_port_forward将一个或多个本地端口转发到podresource_type (字符串), name (字符串), ports (阵列), namespace (字符串,可选), address (字符串,可选)
k8s_cp在容器之间复制文件和目录src_path (字符串), dst_path (字符串), container (字符串,可选), namespace (字符串,可选)
k8s_patch更新资源的字段resource_type (字符串), name (字符串), patch (对象), namespace (字符串,可选)
k8s_标签更新资源上的标签resource_type (字符串), name (字符串), labels (对象), namespace (字符串,可选), overwrite (布尔值,可选)
k8s_注释更新资源上的注释resource_type (字符串), name (字符串), annotations (对象), namespace (字符串,可选), overwrite (布尔值,可选)

Delete Tools

删除工具

这些工具为Kubernetes资源提供删除操作:

工具说明参数
k8s_delete按名称、标签选择器或命名空间中的所有资源删除资源resource_type (字符串), name (字符串,可选), namespace (字符串,可选), label_selector (字符串,可选), all_namespaces (布尔值,可选), force (布尔值,可选), grace_period (整数,可选)

发展

如何在本地运行项目:

uv run -m src.mcp_kubernetes_server.main

如何检查MCP服务器请求和响应:

npx @modelcontextprotocol/inspector uv run -m src.mcp_kubernetes_server.main

故障排除

以下是使用时遇到的一些常见问题及其解决方案 mcp-kubernetes-server:

问题: mcp-kubernetes-server 无法连接到Kubernetes集群或报告身份验证错误。 解决方案:

  • 确保您的 kubeconfig 文件配置正确,并指向预期的集群。
  • 验证您的路径 kubeconfig 文件在中正确指定 mcpServers 配置(对于Docker,确保挂载路径正确;对于 uvx,确保 KUBECONFIG 环境变量设置正确)。
  • 检查您的凭据 kubeconfig 具有在群集上执行操作所需的权限。您可以通过以下方式进行测试 kubectl 直接(例如。, kubectl get pods).

问题: kubectlhelm 命令返回错误,如“找不到命令”或被禁用。 解决方案:

  • 如果通过运行 uvx,确保 kubectlhelm 已安装在您的系统上,并在PATH中可用。有关安装指南,请参阅“先决条件”部分。
  • 如果您看到“不允许写入操作”或“不允许删除操作”之类的消息,则服务器可能已启动,并带有以下标志 --disable-kubectl, --disable-helm, --disable-write,或 --disable-delete。有关这些标志的详细信息,请查看服务器的启动命令和README中的“MCP服务器选项”部分。

问题: 我如何查看我的AI客户端和 mcp-kubernetes-server? 解决方案:

  • 您可以使用 @modelcontextprotocol/inspector “开发”一节中提到的工具: npx @modelcontextprotocol/inspector uv run -m src.mcp_kubernetes_server.main。这将显示正在交换的MCP消息。

问题: 服务器启动,但AI客户端无法连接。 解决方案:

  • 如果使用 stdio 传输(默认为 uvx 直接执行),确保您的AI客户端已配置为启动 mcp-kubernetes-server 命令正确。
  • 如果使用 ssestreamable-http 传输,确保在 mcp-kubernetes-server (例如。, --host 0.0.0.0 --port 8000)可以从您的AI客户端运行的位置访问。检查防火墙规则或网络配置问题。此外,请验证AI客户端是否配置了服务器的正确URL。

贡献

如果您想为该项目做出贡献,请遵循以下准则:

  1. 分叉存储库并将其克隆到本地计算机。
  2. 为您的更改创建一个新分支。
  3. 进行更改,并使用描述性提交消息进行提交。
  4. 将您的更改推送到您的分叉存储库。
  5. 打开对主存储库的拉取请求。

许可证

该项目根据Apache License 2.0获得许可。请参阅 许可证 文件以获取更多详细信息。

目录标签

目录标签

Kubernetes管理PythonClaude自然语言处理developer-toolskubernetesmcpmcp-server混合部署AI助手集成集群诊断DevOps工具

支持客户端

ClaudeCursor

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP