MCP Server that can connect to a Kubernetes cluster and manage it. Supports loading kubeconfig from multiple sources in priority order. Before using this MCP server with any tool, make sure you have: 1. kubectl installed and in your PATH 2. A valid kubeconfig file with contexts configured 3. Access to a Kubernetes cluster configured for kubectl (e.g. minikube, Rancher Desktop, GKE, etc.) 4. Helm v
Add this skill
npx mdskills install Flux159/mcp-server-kubernetesComprehensive Kubernetes management with extensive tool coverage and strong security options
1# MCP Server Kubernetes23[](https://github.com/yourusername/mcp-server-kubernetes/actions/workflows/ci.yml)4[](https://github.com/yourusername/mcp-server-kubernetes)5[](https://bun.sh)6[](https://kubernetes.io/)7[](https://www.docker.com/)8[](https://github.com/Flux159/mcp-server-kubernetes/stargazers)9[](https://github.com/Flux159/mcp-server-kubernetes/issues)10[](https://github.com/Flux159/mcp-server-kubernetes/pulls)11[](https://github.com/Flux159/mcp-server-kubernetes/commits/main)12[](https://archestra.ai/mcp-catalog/flux159__mcp-server-kubernetes)13[](https://deepwiki.com/Flux159/mcp-server-kubernetes)1415<p align="center">16 <img src="https://raw.githubusercontent.com/Flux159/mcp-server-kubernetes/refs/heads/main/icon.png" width="200">17</p>1819MCP Server that can connect to a Kubernetes cluster and manage it. Supports loading kubeconfig from multiple sources in priority order.2021https://github.com/user-attachments/assets/f25f8f4e-4d04-479b-9ae0-5dac452dd2ed2223<a href="https://glama.ai/mcp/servers/w71ieamqrt"><img width="380" height="200" src="https://glama.ai/mcp/servers/w71ieamqrt/badge" /></a>2425## Installation & Usage2627### Prerequisites2829Before using this MCP server with any tool, make sure you have:30311. kubectl installed and in your PATH322. A valid kubeconfig file with contexts configured333. Access to a Kubernetes cluster configured for kubectl (e.g. minikube, Rancher Desktop, GKE, etc.)344. Helm v3 installed and in your PATH (no Tiller required). Optional if you don't plan to use Helm.3536You can verify your connection by running `kubectl get pods` in a terminal to ensure you can connect to your cluster without credential issues.3738By default, the server loads kubeconfig from `~/.kube/config`. For additional authentication options (environment variables, custom paths, etc.), see [ADVANCED_README.md](ADVANCED_README.md).3940### Claude Code4142Add the MCP server to Claude Code using the built-in command:4344```bash45claude mcp add kubernetes -- npx mcp-server-kubernetes46```4748This will automatically configure the server in your Claude Code MCP settings.4950### Claude Desktop5152Add the following configuration to your Claude Desktop config file:5354```json55{56 "mcpServers": {57 "kubernetes": {58 "command": "npx",59 "args": ["mcp-server-kubernetes"]60 }61 }62}63```6465### Claude Desktop Connector via mcpb6667MCP Server Kubernetes is also available as a [mcpb](https://github.com/anthropics/mcpb) (formerly dxt) extension. In Claude Desktop, go to Settings (`Cmd+,` on Mac) -> Extensions -> Browse Extensions and scroll to find mcp-server-kubernetes in the modal. Install it & it will install & utilize kubectl via command line & your kubeconfig.6869To manually install, you can also get the .mcpb by going to the latest [Release](https://github.com/Flux159/mcp-server-kubernetes/releases) and downloading it.7071### VS Code7273[](vscode:mcp/install?%7B%22name%22%3A%20%22kubernetes%22%2C%20%22type%22%3A%20%22stdio%22%2C%20%22command%22%3A%20%22npx%22%2C%20%22args%22%3A%20%5B%22mcp-server-kubernetes%22%5D%7D)7475For VS Code integration, you can use the MCP server with extensions that support the Model Context Protocol:76771. Install a compatible MCP extension (such as Claude Dev or similar MCP clients)782. Configure the extension to use this server:7980```json81{82 "mcpServers": {83 "kubernetes": {84 "command": "npx",85 "args": ["mcp-server-kubernetes"],86 "description": "Kubernetes cluster management and operations"87 }88 }89}90```9192### Cursor9394Cursor supports MCP servers through its AI integration. Add the server to your Cursor MCP configuration:9596```json97{98 "mcpServers": {99 "kubernetes": {100 "command": "npx",101 "args": ["mcp-server-kubernetes"]102 }103 }104}105```106107The server will automatically connect to your current kubectl context. You can verify the connection by asking the AI assistant to list your pods or create a test deployment.108109## Usage with mcp-chat110111[mcp-chat](https://github.com/Flux159/mcp-chat) is a CLI chat client for MCP servers. You can use it to interact with the Kubernetes server.112113```shell114npx mcp-chat --server "npx mcp-server-kubernetes"115```116117Alternatively, pass it your existing Claude Desktop configuration file from above (Linux should pass the correct path to config):118119Mac:120121```shell122npx mcp-chat --config "~/Library/Application Support/Claude/claude_desktop_config.json"123```124125Windows:126127```shell128npx mcp-chat --config "%APPDATA%\Claude\claude_desktop_config.json"129```130131## Gemini CLI132133[Gemini CLI](https://geminicli.com/) allows you to install mcp servers as extensions. From a shell, install the extension by pointing to this repo:134135```shell136gemini extensions install https://github.com/Flux159/mcp-server-kubernetes137```138139## Features140141- [x] Connect to a Kubernetes cluster142- [x] Unified kubectl API for managing resources143 - Get or list resources with `kubectl_get`144 - Describe resources with `kubectl_describe`145 - List resources with `kubectl_get`146 - Create resources with `kubectl_create`147 - Apply YAML manifests with `kubectl_apply`148 - Delete resources with `kubectl_delete`149 - Get logs with `kubectl_logs`150 - Manage kubectl contexts with `kubectl_context`151 - Explain Kubernetes resources with `explain_resource`152 - List API resources with `list_api_resources`153 - Scale resources with `kubectl_scale`154 - Update field(s) of a resource with `kubectl_patch`155 - Manage deployment rollouts with `kubectl_rollout`156 - Execute any kubectl command with `kubectl_generic`157 - Verify connection with `ping`158- [x] Advanced operations159 - Scale deployments with `kubectl_scale` (replaces legacy `scale_deployment`)160 - Port forward to pods and services with `port_forward`161 - Run Helm operations162 - Install, upgrade, and uninstall charts163 - Support for custom values, repositories, and versions164 - Template-based installation (`helm_template_apply`) to bypass authentication issues165 - Template-based uninstallation (`helm_template_uninstall`) to bypass authentication issues166 - Pod cleanup operations167 - Clean up problematic pods (`cleanup_pods`) in states: Evicted, ContainerStatusUnknown, Completed, Error, ImagePullBackOff, CrashLoopBackOff168 - Node management operations169 - Cordoning, draining, and uncordoning nodes (`node_management`) for maintenance and scaling operations170- [x] Troubleshooting Prompt (`k8s-diagnose`)171 - Guides through a systematic Kubernetes troubleshooting flow for pods based on a keyword and optional namespace.172- [x] Non-destructive mode for read and create/update-only access to clusters173- [x] Secrets masking for security (masks sensitive data in `kubectl get secrets` commands, does not affect logs)174175## Prompts176177The MCP Kubernetes server includes specialized prompts to assist with common diagnostic operations.178179### /k8s-diagnose Prompt180181This prompt provides a systematic troubleshooting flow for Kubernetes pods. It accepts a `keyword` to identify relevant pods and an optional `namespace` to narrow the search.182The prompt's output will guide you through an autonomous troubleshooting flow, providing instructions for identifying issues, collecting evidence, and suggesting remediation steps.183184## Local Development185186Make sure that you have [bun installed](https://bun.sh/docs/installation). Clone the repo & install dependencies:187188```bash189git clone https://github.com/Flux159/mcp-server-kubernetes.git190cd mcp-server-kubernetes191bun install192```193194### Development Workflow1951961. Start the server in development mode (watches for file changes):197198```bash199bun run dev200```2012022. Run unit tests:203204```bash205bun run test206```2072083. Build the project:209210```bash211bun run build212```2132144. Local Testing with [Inspector](https://github.com/modelcontextprotocol/inspector)215216```bash217npx @modelcontextprotocol/inspector node dist/index.js218# Follow further instructions on terminal for Inspector link219```2202215. Local testing with Claude Desktop222223```json224{225 "mcpServers": {226 "mcp-server-kubernetes": {227 "command": "node",228 "args": ["/path/to/your/mcp-server-kubernetes/dist/index.js"]229 }230 }231}232```2332346. Local testing with [mcp-chat](https://github.com/Flux159/mcp-chat)235236```bash237bun run chat238```239240## Contributing241242See the [CONTRIBUTING.md](CONTRIBUTING.md) file for details.243244## Advanced245246### Non-Destructive Mode247248You can run the server in a non-destructive mode that disables all destructive operations (delete pods, delete deployments, delete namespaces, etc.):249250```shell251ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS=true npx mcp-server-kubernetes252```253254For Claude Desktop configuration with non-destructive mode:255256```json257{258 "mcpServers": {259 "kubernetes-readonly": {260 "command": "npx",261 "args": ["mcp-server-kubernetes"],262 "env": {263 "ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS": "true"264 }265 }266 }267}268```269270### Commands Available in Non-Destructive Mode271272All read-only and resource creation/update operations remain available:273274- Resource Information: `kubectl_get`, `kubectl_describe`, `kubectl_logs`, `explain_resource`, `list_api_resources`275- Resource Creation/Modification: `kubectl_apply`, `kubectl_create`, `kubectl_scale`, `kubectl_patch`, `kubectl_rollout`276- Helm Operations: `install_helm_chart`, `upgrade_helm_chart`, `helm_template_apply`, `helm_template_uninstall`277- Connectivity: `port_forward`, `stop_port_forward`278- Context Management: `kubectl_context`279280### Commands Disabled in Non-Destructive Mode281282The following destructive operations are disabled:283284- `kubectl_delete`: Deleting any Kubernetes resources285- `uninstall_helm_chart`: Uninstalling Helm charts286- `cleanup`: Cleanup of managed resources287- `cleanup_pods`: Cleaning up problematic pods288- `node_management`: Node management operations (can drain nodes)289- `kubectl_generic`: General kubectl command access (may include destructive operations)290291For additional advanced features, see the [ADVANCED_README.md](ADVANCED_README.md) and also the [docs](https://github.com/Flux159/mcp-server-kubernetes/tree/main/docs) folder for specific information on `helm_install`, `helm_template_apply`, node management & pod cleanup.292293## Architecture294295See this [DeepWiki link](https://deepwiki.com/Flux159/mcp-server-kubernetes) for a more indepth architecture overview created by Devin.296297This section describes the high-level architecture of the MCP Kubernetes server.298299### Request Flow300301The sequence diagram below illustrates how requests flow through the system:302303```mermaid304sequenceDiagram305 participant Client306 participant Transport as Transport Layer307 participant Server as MCP Server308 participant Filter as Tool Filter309 participant Handler as Request Handler310 participant K8sManager as KubernetesManager311 participant K8s as Kubernetes API312313 Note over Transport: StdioTransport or<br>SSE Transport314315 Client->>Transport: Send Request316 Transport->>Server: Forward Request317318 alt Tools Request319 Server->>Filter: Filter available tools320 Note over Filter: Remove destructive tools<br>if in non-destructive mode321 Filter->>Handler: Route to tools handler322323 alt kubectl operations324 Handler->>K8sManager: Execute kubectl operation325 K8sManager->>K8s: Make API call326 else Helm operations327 Handler->>K8sManager: Execute Helm operation328 K8sManager->>K8s: Make API call329 else Port Forward operations330 Handler->>K8sManager: Set up port forwarding331 K8sManager->>K8s: Make API call332 end333334 K8s-->>K8sManager: Return result335 K8sManager-->>Handler: Process response336 Handler-->>Server: Return tool result337 else Resource Request338 Server->>Handler: Route to resource handler339 Handler->>K8sManager: Get resource data340 K8sManager->>K8s: Query API341 K8s-->>K8sManager: Return data342 K8sManager-->>Handler: Format response343 Handler-->>Server: Return resource data344 end345346 Server-->>Transport: Send Response347 Transport-->>Client: Return Final Response348```349350See this [DeepWiki link](https://deepwiki.com/Flux159/mcp-server-kubernetes) for a more indepth architecture overview created by Devin.351352## Publishing new release353354Go to the [releases page](https://github.com/Flux159/mcp-server-kubernetes/releases), click on "Draft New Release", click "Choose a tag" and create a new tag by typing out a new version number using "v{major}.{minor}.{patch}" semver format. Then, write a release title "Release v{major}.{minor}.{patch}" and description / changelog if necessary and click "Publish Release".355356This will create a new tag which will trigger a new release build via the cd.yml workflow. Once successful, the new release will be published to [npm](https://www.npmjs.com/package/mcp-server-kubernetes). Note that there is no need to update the package.json version manually, as the workflow will automatically update the version number in the package.json file & push a commit to main.357358## Not planned359360Adding clusters to kubectx.361362## Star History363364[](https://www.star-history.com/#Flux159/mcp-server-kubernetes&Date)365366## ๐๏ธ Cite367368If you find this repo useful, please cite:369370```371@software{Patel_MCP_Server_Kubernetes_2024,372author = {Patel, Paras and Sonwalkar, Suyog},373month = jul,374title = {{MCP Server Kubernetes}},375url = {https://github.com/Flux159/mcp-server-kubernetes},376version = {2.5.0},377year = {2024}378}379```380
Full transparency โ inspect the skill content before installing.