Skip to main content
Glama

Kubernetes Monitor

by vlttnv
MIT License
1
  • Apple
  • Linux

k8s-mcp

一个基于 Python 的、用于 Kubernetes 集群的只读模型上下文协议 (MCP)服务器,它公开了一个全面的 API 来检索集群信息和诊断问题。

使用 Claude 的示例聊天

安装

先决条件

  • Python 3.8+
  • 访问 Kubernetes 集群(通过 kubeconfig 或集群内配置)
  • 所需的 Python 包(请参阅pyproject.toml中的dependencies
  • 紫外线 - https://github.com/astral-sh/uv
# To install uv curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone the repository git clone git@github.com:vlttnv/k8s-mcp.git cd k8s-mcp # Install dependencies uv venv source .venv/bin/activate uv sync

如果使用 Claude 配置,请在文本编辑器中打开 Claude 桌面应用配置:~/Library/Application Support/Claude/claude_desktop_config.json。如果该文件不存在,请务必创建。

code ~/Library/Application\ Support/Claude/claude_desktop_config.json
{ "mcpServers": { "k8s-mcp": { "command": "uv", "args": [ "--directory", "/ABSOLUTE/PATH/TO/PARENT/FOLDER/k8s-mcp", "run", "server.py" ] } } }

您可能需要在命令字段中输入 uv 可执行文件的完整路径。您可以在 MacOS/Linux 上运行 which uv 或在 Windows 上运行 where uv 来获取此路径。

配置

应用程序会自动尝试两种方法连接到您的 Kubernetes 集群:

  1. Kubeconfig 文件:使用本地 kubeconfig 文件(通常位于~/.kube/config
  2. 集群内配置:如果在 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() :列出所有处于失败或错误状态的 pod
  • pending_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 配置

执照

MIT 许可证

贡献

欢迎贡献代码!欢迎提交 Pull 请求。

-
security - not tested
A
license - permissive license
-
quality - not tested

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Kubernetes 的只读 MCP 服务器,允许通过 Claude 等自然语言界面查询集群信息和诊断问题。

  1. 安装
    1. 先决条件
  2. 配置
    1. 用法
      1. 示例
    2. API 参考
      1. 命名空间
      2. 豆荚
      3. 节点
      4. 部署和服务
      5. 资源管理
    3. 执照
      1. 贡献

        Related MCP Servers

        • A
          security
          F
          license
          A
          quality
          A MCP server that can run Kubernetes commands with a given kubeconfig path and provide interpretation of the commands.
          Last updated -
          1
          2
          JavaScript
          • Apple
        • -
          security
          A
          license
          -
          quality
          An 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 -
          Python
          MIT License
        • -
          security
          F
          license
          -
          quality
          A 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 -
          3
          Python
        • -
          security
          A
          license
          -
          quality
          A 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 -
          604
          Python
          MIT License
          • Linux
          • Apple

        View all related MCP servers

        MCP directory API

        We provide all the information about MCP servers via our MCP API.

        curl -X GET 'https://glama.ai/api/mcp/v1/servers/vlttnv/k8s-mcp'

        If you have feedback or need assistance with the MCP directory API, please join our Discord server