使用说明
mcp服务器kubernetes
MCP(模型上下文协议)服务器,提供与Kubernetes集群交互的工具,包括Pod、部署、服务、命名空间、事件和清单管理。
建筑
graph TB
subgraph Client
style Client fill:#4A90D9,stroke:#2E6BA6,color:#FFFFFF
MCP_Client["MCP Client"]
end
subgraph Server["mcp-server-kubernetes"]
style Server fill:#2ECC71,stroke:#1A9B52,color:#FFFFFF
Index["index.ts<br/>MCP Server Entry"]
subgraph Tools
style Tools fill:#F39C12,stroke:#C67D0A,color:#FFFFFF
T1["list_pods"]
T2["list_deployments"]
T3["list_services"]
T4["get_pod_logs"]
T5["apply_manifest"]
T6["list_namespaces"]
T7["get_events"]
T8["scale_deployment"]
end
end
subgraph K8s["Kubernetes Cluster"]
style K8s fill:#326CE5,stroke:#1E4FA0,color:#FFFFFF
API["API Server"]
subgraph Resources
style Resources fill:#E74C3C,stroke:#B83A2E,color:#FFFFFF
Pods["Pods"]
Deploys["Deployments"]
Svcs["Services"]
NS["Namespaces"]
Events["Events"]
end
end
MCP_Client -- "stdio transport" --> Index
Index --> T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8
T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 --> API
API --> Pods & Deploys & Svcs & NS & Events
安装
npm install
npm run build
配置
服务器使用默认的kubeconfig文件(~/.kube/config)或者在Kubernetes内部运行时在集群配置中。
| 变量 | 描述 | 必填 |
|---|---|---|
KUBECONFIG |
kubeconfig文件的路径 | 否(默认为 ~/.kube/config) |
用法
独立
npm start
发展
npm run dev
码头工人
docker build -t mcp-server-kubernetes .
docker run -v ~/.kube/config:/root/.kube/config:ro mcp-server-kubernetes
MCP客户端配置
{
"mcpServers": {
"kubernetes": {
"command": "node",
"args": ["dist/index.js"],
"env": {
"KUBECONFIG": "/path/to/kubeconfig"
}
}
}
}
工具参考
| 工具 | 说明 | 参数 |
|---|---|---|
list_pods |
列出Pod | namespace?, label_selector? |
list_deployments |
列出部署 | namespace? |
list_services |
列出服务 | namespace? |
get_pod_logs |
获取pod日志 | namespace, pod_name, container?, tail_lines? |
apply_manifest |
应用K8s清单 | manifest (YAML字符串) |
list_namespaces |
列出命名空间 | 无 |
get_events |
获取集群事件 | namespace? |
scale_deployment |
扩展部署 | namespace, deployment_name, replicas |
许可证
麻省理工学院
