Kubernetes MCP Server
Enables AI assistants to interact with Kubernetes clusters through 50 specialized tools for comprehensive cluster management. Supports both local kubectl and remote SSH-based execution for managing pods, deployments, services, and other Kubernetes resources.
README
Kubernetes MCP Server
A Model Context Protocol (MCP) server that provides comprehensive Kubernetes cluster management capabilities. This server enables AI assistants like Claude to interact with Kubernetes clusters through 50 specialized tools, supporting both local kubectl and remote SSH-based execution.
Features
50 Kubernetes Management Tools
This MCP server provides complete cluster management capabilities organized into the following categories:
Cluster Management (4 tools)
k8s_get_cluster_info- Get cluster information including server version and endpointsk8s_list_nodes- List all nodes with status, roles, and resource informationk8s_get_node- Get detailed information about a specific nodek8s_describe_node- Get full node description including conditions and capacity
Namespace Management (3 tools)
k8s_list_namespaces- List all namespaces in the clusterk8s_create_namespace- Create a new namespacek8s_delete_namespace- Delete a namespace (with warning)
Pod Management (6 tools)
k8s_list_pods- List pods with filtering by namespace and labelsk8s_get_pod- Get detailed pod informationk8s_describe_pod- Get full pod description including eventsk8s_get_pod_logs- Get container logs with filtering optionsk8s_delete_pod- Delete a pod (with optional force)k8s_exec_pod- Execute commands in pod containers
Deployment Management (6 tools)
k8s_list_deployments- List deployments in namespace or cluster-widek8s_get_deployment- Get detailed deployment informationk8s_describe_deployment- Get full deployment description with eventsk8s_scale_deployment- Scale deployment replicask8s_restart_deployment- Perform rolling restartk8s_update_deployment_image- Update container image
Service Management (3 tools)
k8s_list_services- List services in namespace or cluster-widek8s_get_service- Get detailed service informationk8s_describe_service- Get full service description including endpoints
ConfigMap Management (4 tools)
k8s_list_configmaps- List ConfigMaps in namespacek8s_get_configmap- Get ConfigMap details and datak8s_create_configmap- Create ConfigMap from literal valuesk8s_delete_configmap- Delete a ConfigMap
Secret Management (4 tools)
k8s_list_secrets- List secrets (values hidden)k8s_get_secret- Get secret metadata (with optional decode)k8s_create_secret- Create secret from literal valuesk8s_delete_secret- Delete a secret
StatefulSet Management (3 tools)
k8s_list_statefulsets- List StatefulSets in namespacek8s_get_statefulset- Get StatefulSet detailsk8s_scale_statefulset- Scale StatefulSet replicas
DaemonSet Management (2 tools)
k8s_list_daemonsets- List DaemonSets in namespacek8s_get_daemonset- Get DaemonSet details
Ingress Management (2 tools)
k8s_list_ingresses- List Ingresses in namespacek8s_get_ingress- Get Ingress details
Resource Management (5 tools)
k8s_apply_manifest- Apply YAML/JSON manifest to clusterk8s_delete_resource- Delete resource by type and namek8s_get_events- Get cluster events with optional filteringk8s_get_resource_yaml- Get any resource as YAMLk8s_get_all- Get all common resources in namespace
Rollout Management (3 tools)
k8s_rollout_status- Get deployment rollout statusk8s_rollout_history- Get rollout historyk8s_rollout_undo- Undo deployment rollout
Metrics & Monitoring (2 tools)
k8s_top_nodes- Show node resource usage (CPU/memory)k8s_top_pods- Show pod resource usage (CPU/memory)
Context Management (2 tools)
k8s_get_contexts- List all available kubectl contextsk8s_current_context- Get current kubectl context
Installation
Prerequisites
- Node.js 20 or higher
- TypeScript 5.3 or higher
- kubectl installed and configured (for local mode)
- SSH access configured (for remote mode)
Setup
- Clone this repository:
git clone https://github.com/yourusername/mcp-kubernetes.git
cd mcp-kubernetes
- Install dependencies:
npm install
- Build the TypeScript source:
npm run build
Configuration
Environment Variables
The server supports both local kubectl execution and remote SSH-based execution:
Local kubectl Mode
KUBECONFIG(optional) - Path to kubeconfig file (defaults to ~/.kube/config)K8S_CONTEXT(optional) - Specific kubectl context to useK8S_DEFAULT_NAMESPACE(optional) - Default namespace (defaults to "default")KUBECTL_PATH(optional) - Path to kubectl binary (defaults to "kubectl")
Remote SSH Mode (for K3s or remote clusters)
K8S_SSH_HOST- SSH host for remote kubectl execution (e.g., 192.168.16.100)K8S_SSH_USER- SSH username for authenticationK8S_SSH_KEY- Path to SSH private key for authenticationK8S_SSH_PASSWORD(alternative) - SSH password (uses plink on Windows, sshpass on Linux)K8S_DEFAULT_NAMESPACE(optional) - Default namespace (defaults to "default")
Claude Desktop Configuration
Add to your Claude desktop configuration file (~/.claude/config.json or %APPDATA%\Claude\config.json on Windows):
Local kubectl:
{
"mcpServers": {
"kubernetes": {
"type": "stdio",
"command": "node",
"args": ["/path/to/mcp-kubernetes/dist/index.js"],
"env": {
"K8S_DEFAULT_NAMESPACE": "default"
}
}
}
}
Remote SSH (K3s/Raspberry Pi example):
{
"mcpServers": {
"kubernetes": {
"type": "stdio",
"command": "node",
"args": ["C:/Users/Administrator/mcp-servers/kubernetes/dist/index.js"],
"env": {
"K8S_SSH_HOST": "192.168.16.100",
"K8S_SSH_USER": "mark",
"K8S_SSH_KEY": "C:/Users/Administrator/.ssh/id_ed25519_k8s",
"K8S_DEFAULT_NAMESPACE": "default"
}
}
}
}
Usage Examples
List all pods in a namespace
// Using the k8s_list_pods tool
{
"namespace": "default"
}
Get pod logs
// Using the k8s_get_pod_logs tool
{
"name": "my-pod",
"namespace": "default",
"tail": 100,
"since": "5m"
}
Scale a deployment
// Using the k8s_scale_deployment tool
{
"name": "my-deployment",
"namespace": "default",
"replicas": 3
}
Apply a manifest
// Using the k8s_apply_manifest tool
{
"manifest": "apiVersion: v1\nkind: Pod\n...",
"namespace": "default"
}
Execute command in pod
// Using the k8s_exec_pod tool
{
"name": "my-pod",
"namespace": "default",
"command": "ls -la /app"
}
Get cluster events
// Using the k8s_get_events tool
{
"namespace": "default"
}
Development
Running in development mode
npm run dev
Building for production
npm run build
Starting the server
npm start
Architecture
The server uses the Model Context Protocol (MCP) to expose Kubernetes operations as tools. It supports two execution modes:
- Local Mode: Executes kubectl commands directly on the local machine
- Remote SSH Mode: Executes kubectl commands on a remote server via SSH (useful for K3s clusters or remote Kubernetes installations)
The server automatically detects which mode to use based on the presence of SSH environment variables.
Use Cases
- Raspberry Pi K3s Clusters: Manage lightweight K3s clusters remotely
- Development Clusters: Quick operations on local development clusters
- Production Monitoring: Read-only operations for cluster health monitoring
- GitOps Workflows: Apply manifests and track deployments
- Troubleshooting: Get logs, describe resources, check events
- Resource Management: Create/delete ConfigMaps, Secrets, and other resources
Security Considerations
- SSH Key Authentication: Prefer SSH key authentication over password-based auth
- Read-Only Operations: Many tools are read-only and safe for production
- Secret Handling: Secrets are base64 encoded by default; decode only when necessary
- Namespace Isolation: Use namespace parameters to limit scope of operations
- Force Operations: Be cautious with
forceparameters on delete operations
Tested Environments
- K3s on Raspberry Pi (v1.33.5+k3s1)
- Local Kubernetes (minikube, kind, Docker Desktop)
- Remote Kubernetes via SSH
Limitations
- Requires
kubectlto be installed and accessible - SSH mode requires sudo access for kubectl on remote host
- Metrics tools require metrics-server to be installed in the cluster
- Windows SSH password auth requires PuTTY's plink to be available
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details
Acknowledgments
- Built with the Model Context Protocol SDK
- Designed for use with Claude Desktop
- Inspired by the Kubernetes community's kubectl tool
Support
For issues, questions, or contributions, please open an issue on GitHub.
Version History
- 1.0.0 - Initial release with 50 Kubernetes management tools
- Full support for pods, deployments, services, ConfigMaps, secrets
- StatefulSets, DaemonSets, Ingresses
- Rollout management and metrics
- Local and remote SSH execution modes
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。