MCP服务器Kubernetes(Python)
使用FastMCP和Python Kubernetes客户端进行Kubernetes集群检查的只读MCP服务器。
~~复制~~深受启发 Flux159/mcp服务器kubernetes
安装```bash
uv pip install -e .
## 用法```bash
uv run python -m mcp_server_k8s.server
示例用法
获取Pod```bash
Via Claude Code or Claude Desktop
"Show me all pods in default namespace"
"List pods with label app=nginx in production namespace"
### 描述资源```bash
"Describe the deployment called my-app"
"Show details of pod my-pod-123 in namespace staging"
查看日志```bash
"Show logs from pod my-pod"
"Get the last 50 lines of logs from deployment nginx"
"Show logs from the app container in pod multi-container-pod"
### 故障排除```bash
"Diagnose issues with pods matching 'api'"
"/k8s-diagnose keyword=backend namespace=production"
健康检查```bash
"Ping the Kubernetes cluster"
"Check if cluster is accessible"
## 工具参考
|工具|说明|关键参数|
|------|-------------|----------------|
| `kubectl_get` |获取/列出资源|资源类型、名称、命名空间、标签选择器|
| `kubectl_get_paginated` |分页列表|资源类型、命名空间、限制、继续|
| `kubectl_describe` |详细资源信息|resourceType、名称、命名空间|
| `kubectl_logs` |容器日志|资源类型、名称、命名空间、容器、尾部|
| `ping` |健康检查|无|
## 故障排除
### “无法连接到群集”
检查:
1. `~/.kube/config` 存在且有效
1. 当前上下文已设置: `kubectl config current-context`
1. 您可以通过网络访问群集
### “找不到资源”
验证:
1. 资源名称正确
1. 命名空间正确(默认值:“default”)
1. 您有RBAC权限查看资源
### “多容器吊舱需要容器规格”
对于具有多个容器的Pod,请指定哪个容器:```
"Show logs from container nginx in pod my-pod"
Claude桌面配置```json
{
"mcpServers": {
"kubernetes": {
"command": "uv",
"args": ["run", "python", "-m", "mcp_server_k8s.server"]
}
}
}
## 特性
- kubectl_get-获取/列出资源
- kubectl_get_paginated-分页资源列表
- kubectl_describe-详细的资源描述
- kubectl_logs-Pod/部署日志
- ping-健康检查
- k8s诊断提示-故障排除流程
## 发展```bash
# Install dev dependencies
uv pip install -e ".[dev]"
# Run tests
pytest
