k8s-mcp
一个基于 Python 的、用于 Kubernetes 集群的只读模型上下文协议 (MCP)服务器,它公开了一个全面的 API 来检索集群信息和诊断问题。
安装
先决条件
- Python 3.8+
- 访问 Kubernetes 集群(通过 kubeconfig 或集群内配置)
- 所需的 Python 包(请参阅
pyproject.toml
中的dependencies
) - 紫外线 - https://github.com/astral-sh/uv
如果使用 Claude 配置,请在文本编辑器中打开 Claude 桌面应用配置:~/Library/Application Support/Claude/claude_desktop_config.json。如果该文件不存在,请务必创建。
您可能需要在命令字段中输入 uv 可执行文件的完整路径。您可以在 MacOS/Linux 上运行 which uv 或在 Windows 上运行 where uv 来获取此路径。
配置
应用程序会自动尝试两种方法连接到您的 Kubernetes 集群:
- Kubeconfig 文件:使用本地 kubeconfig 文件(通常位于
~/.kube/config
) - 集群内配置:如果在 Kubernetes pod 内运行,则使用服务帐户令牌
如果您的 kubeconfig 设置正确或者您在具有适当 RBAC 权限的集群内运行,则无需进行其他配置。
用法
示例
以下是一些有用的示例提示,您可以向 Claude 询问有关您的 Kubernetes 集群及其资源的问题:
常规集群状态
- “我的集群的整体健康状况如何?”
- “显示我的集群中的所有命名空间”
- “我的集群中有哪些可用节点以及它们的状态如何?”
- “我的节点的资源利用率如何?”
Pod 和 Deployment
- “列出生产命名空间中的所有 pod”
- “是否有处于 CrashLoopBackOff 状态的 Pod?”
- “显示重启次数较多的 Pod”
- “列出所有命名空间中的所有部署”
- “哪些部署未能取得进展?”
调试问题
- “为什么我的 staging 命名空间中的 pod 会失败?”
- “获取生产命名空间中服务的 YAML 配置”
- “显示默认命名空间中最近的事件”
- “是否有任何 Pod 处于待处理状态?”
- “是什么原因导致我的集群出现 ImagePullBackOff 错误?”
资源管理
- “显示我的集群中节点的资源消耗情况”
- “是否有我应该清理的孤立资源?”
- “列出生产命名空间中的所有服务”
- “比较暂存和生产之间的资源请求”
特定资源检查
- “向我展示 kube-system 中 coredns 部署的配置”
- “获取暂存中的反向代理服务的详细信息”
- “pod xyz 中正在运行哪些容器?”
- “显示故障 Pod 的日志”
API 参考
命名空间
get_namespaces()
:列出集群中所有可用的命名空间
豆荚
list_pods(namespace=None)
:列出所有 pod,可选择按命名空间进行过滤failed_pods()
:列出所有处于失败或错误状态的 podpending_pods()
:列出所有处于 Pending 状态的 pod 及其原因high_restart_pods(restart_threshold=5)
:查找重启次数超过阈值的 pod
节点
list_nodes()
:列出所有节点及其状态node_capacity()
:显示所有节点的可用容量
部署和服务
list_deployments(namespace=None)
:列出所有部署list_services(namespace=None)
:列出所有服务list_events(namespace=None)
:列出所有事件
资源管理
orphaned_resources()
:列出没有所有者引用的资源get_resource_yaml(namespace, resource_type, resource_name)
:获取特定资源的 YAML 配置
执照
贡献
欢迎贡献代码!欢迎提交 Pull 请求。
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Kubernetes 的只读 MCP 服务器,允许通过 Claude 等自然语言界面查询集群信息和诊断问题。
Related Resources
Related MCP Servers
- AsecurityFlicenseAqualityA MCP server that can run Kubernetes commands with a given kubeconfig path and provide interpretation of the commands.Last updated -12JavaScript
- -securityAlicense-qualityAn MCP server that enables interaction with Kubernetes/Minikube clusters through natural language, allowing AI agents like Codename Goose to manage Kubernetes resources via the Model Context Protocol.Last updated -PythonMIT License
- -securityFlicense-qualityA server that enables LLMs to manage Kubernetes clusters through natural language commands, wrapping kubectl operations to provide a simplified interface for common Kubernetes tasks.Last updated -3Python
- -securityAlicense-qualityA Model Context Protocol server that enables AI assistants to interact with Kubernetes clusters through natural language, supporting core Kubernetes operations, monitoring, security, and diagnostics.Last updated -604PythonMIT License