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