使用说明
Kubernetes MCP服务器
一个轻量级的MCP服务器,提供对Kubernetes集群的自然语言处理和API访问,结合了kubectl命令和KubernetesPython客户端。
https://github.com/user-attachments/assets/48e061cd-3e85-40ff-ab04-a1a2b9bbd152
✨ 特性
- 自然语言接口:将纯英文查询转换为kubectl命令
- 列出所有命名空间中的Pod和部署
- 对于不支持的查询,回退到常规资源列表
- 完整的CRUD操作:
- 🆕 通过API端点创建/删除命名空间、pod和部署
- 🔍 检查群集资源
- ✏️ 修改标签、注释和部署配置
- 🗑️ 优雅删除
- 📊 扩展部署
- 双执行模式:
kubectl指挥集成- Kubernetes Python客户端(官方SDK)
- 高性能:
- 命名空间验证(符合DNS-1123标准)
- 标签过滤
- 宽限期控制
- 自动命令回退
- 资源管理(CPU、内存)
- 环境变量配置
📦 安装
先决条件
- Python 3.11+
- Kubernetes集群访问
kubectl本地配置- 紫外线的 安装
# Clone repository
git clone https://github.com/ductnn/mcp-kubernetes-server.git
cd mcp-kubernetes-server
# Create virtual environment
uv venv .venv
# Activate (Unix)
source .venv/bin/activate
# Install dependencies
uv pip install -r requirements.txt
🚀 用法
自然语言处理
服务器支持列出资源的基本自然语言查询:
# List all pods
result = nl_processor.process("Show me all pods")
# List all deployments
result = nl_processor.process("Show me all deployments")
# Query with namespace
result = nl_processor.process("Show me all resources", "kube-system")
对于更复杂的操作,请使用专用的API端点:
# Create a pod
pod_service.create_pod(
name="my-pod",
namespace="default",
image="nginx:latest",
labels={"app": "my-app"}
)
# Create a deployment
deployment_service.create_deployment(
name="my-deployment",
namespace="default",
image="nginx:latest",
replicas=3
)
# Delete a namespace
namespace_service.delete("my-namespace", force=True)
API终点
服务器为所有操作提供RESTful端点:
/api/pods-吊舱操作/api/deployments-部署操作/api/namespaces-命名空间操作/api/cluster-集群操作/api/nlp-自然语言处理
🤖 使用AI助手
克劳德桌面
- 打开你的 克劳德桌面 并选择
Settings->选择模式Developer->Edit config并打开文件claude_desktop_config.json并编辑:
{
"mcpServers": {
"kubernetes": {
"command": "/path-to-your-uv/uv",
"args": [
"--directory",
"/path-you-project/", // Example for me /Users/ductn/mcp-kubernetes-server
"run",
"main.py"
]
}
}
}
- 然后,重新启动您的克劳德桌面并播放:)
🧪 测试
运行测试套件:
# Run all tests
pytest
# Run specific test file
pytest tests/unit/test_pod_service.py
# Run with coverage
pytest --cov=.
📝 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
