mcp-server-kubernetes 2.9.0 → 2.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -10
- package/dist/tools/kubectl-context.js +27 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
[](https://github.com/Flux159/mcp-server-kubernetes/pulls)
|
|
11
11
|
[](https://github.com/Flux159/mcp-server-kubernetes/commits/main)
|
|
12
12
|
[](https://archestra.ai/mcp-catalog/flux159__mcp-server-kubernetes)
|
|
13
|
+
[](https://deepwiki.com/Flux159/mcp-server-kubernetes)
|
|
13
14
|
|
|
14
15
|
MCP Server that can connect to a Kubernetes cluster and manage it. Supports loading kubeconfig from multiple sources in priority order.
|
|
15
16
|
|
|
@@ -17,7 +18,34 @@ https://github.com/user-attachments/assets/f25f8f4e-4d04-479b-9ae0-5dac452dd2ed
|
|
|
17
18
|
|
|
18
19
|
<a href="https://glama.ai/mcp/servers/w71ieamqrt"><img width="380" height="200" src="https://glama.ai/mcp/servers/w71ieamqrt/badge" /></a>
|
|
19
20
|
|
|
20
|
-
##
|
|
21
|
+
## Installation & Usage
|
|
22
|
+
|
|
23
|
+
### Prerequisites
|
|
24
|
+
|
|
25
|
+
Before using this MCP server with any tool, make sure you have:
|
|
26
|
+
|
|
27
|
+
1. kubectl installed and in your PATH
|
|
28
|
+
2. A valid kubeconfig file with contexts configured
|
|
29
|
+
3. Access to a Kubernetes cluster configured for kubectl (e.g. minikube, Rancher Desktop, GKE, etc.)
|
|
30
|
+
4. Helm v3 installed and in your PATH (no Tiller required). Optional if you don't plan to use Helm.
|
|
31
|
+
|
|
32
|
+
You can verify your connection by running `kubectl get pods` in a terminal to ensure you can connect to your cluster without credential issues.
|
|
33
|
+
|
|
34
|
+
By default, the server loads kubeconfig from `~/.kube/config`. For additional authentication options (environment variables, custom paths, etc.), see [ADVANCED_README.md](ADVANCED_README.md).
|
|
35
|
+
|
|
36
|
+
### Claude Code
|
|
37
|
+
|
|
38
|
+
Add the MCP server to Claude Code using the built-in command:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
claude mcp add kubernetes -- npx mcp-server-kubernetes
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
This will automatically configure the server in your Claude Code MCP settings.
|
|
45
|
+
|
|
46
|
+
### Claude Desktop
|
|
47
|
+
|
|
48
|
+
Add the following configuration to your Claude Desktop config file:
|
|
21
49
|
|
|
22
50
|
```json
|
|
23
51
|
{
|
|
@@ -30,18 +58,43 @@ https://github.com/user-attachments/assets/f25f8f4e-4d04-479b-9ae0-5dac452dd2ed
|
|
|
30
58
|
}
|
|
31
59
|
```
|
|
32
60
|
|
|
33
|
-
|
|
61
|
+
### VS Code
|
|
34
62
|
|
|
35
|
-
|
|
63
|
+
[](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)
|
|
36
64
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
65
|
+
For VS Code integration, you can use the MCP server with extensions that support the Model Context Protocol:
|
|
66
|
+
|
|
67
|
+
1. Install a compatible MCP extension (such as Claude Dev or similar MCP clients)
|
|
68
|
+
2. Configure the extension to use this server:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"mcpServers": {
|
|
73
|
+
"kubernetes": {
|
|
74
|
+
"command": "npx",
|
|
75
|
+
"args": ["mcp-server-kubernetes"],
|
|
76
|
+
"description": "Kubernetes cluster management and operations"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
41
81
|
|
|
42
|
-
|
|
82
|
+
### Cursor
|
|
43
83
|
|
|
44
|
-
|
|
84
|
+
Cursor supports MCP servers through its AI integration. Add the server to your Cursor MCP configuration:
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"mcpServers": {
|
|
89
|
+
"kubernetes": {
|
|
90
|
+
"command": "npx",
|
|
91
|
+
"args": ["mcp-server-kubernetes"]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The 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.
|
|
45
98
|
|
|
46
99
|
## Usage with mcp-chat
|
|
47
100
|
|
|
@@ -105,7 +158,7 @@ npx mcp-chat --config "%APPDATA%\Claude\claude_desktop_config.json"
|
|
|
105
158
|
|
|
106
159
|
The MCP Kubernetes server includes specialized prompts to assist with common diagnostic operations.
|
|
107
160
|
|
|
108
|
-
### k8s-diagnose Prompt
|
|
161
|
+
### /k8s-diagnose Prompt
|
|
109
162
|
|
|
110
163
|
This 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.
|
|
111
164
|
The prompt's output will guide you through an autonomous troubleshooting flow, providing instructions for identifying issues, collecting evidence, and suggesting remediation steps.
|
|
@@ -248,6 +301,7 @@ Instead of using `helm install` directly, this tool:
|
|
|
248
301
|
```
|
|
249
302
|
|
|
250
303
|
This is equivalent to running:
|
|
304
|
+
|
|
251
305
|
```bash
|
|
252
306
|
helm template events-exporter . -f values.yaml > events-exporter.yaml
|
|
253
307
|
kubectl create namespace kube-event-exporter
|
|
@@ -273,6 +327,7 @@ Pod cleanup can be achieved using the existing `kubectl_get` and `kubectl_delete
|
|
|
273
327
|
Use `kubectl_get` with field selectors to identify pods in problematic states:
|
|
274
328
|
|
|
275
329
|
**Get failed pods:**
|
|
330
|
+
|
|
276
331
|
```json
|
|
277
332
|
{
|
|
278
333
|
"name": "kubectl_get",
|
|
@@ -285,6 +340,7 @@ Use `kubectl_get` with field selectors to identify pods in problematic states:
|
|
|
285
340
|
```
|
|
286
341
|
|
|
287
342
|
**Get completed pods:**
|
|
343
|
+
|
|
288
344
|
```json
|
|
289
345
|
{
|
|
290
346
|
"name": "kubectl_get",
|
|
@@ -297,6 +353,7 @@ Use `kubectl_get` with field selectors to identify pods in problematic states:
|
|
|
297
353
|
```
|
|
298
354
|
|
|
299
355
|
**Get pods with specific conditions:**
|
|
356
|
+
|
|
300
357
|
```json
|
|
301
358
|
{
|
|
302
359
|
"name": "kubectl_get",
|
|
@@ -313,6 +370,7 @@ Use `kubectl_get` with field selectors to identify pods in problematic states:
|
|
|
313
370
|
Use `kubectl_delete` with field selectors to delete pods in problematic states:
|
|
314
371
|
|
|
315
372
|
**Delete failed pods:**
|
|
373
|
+
|
|
316
374
|
```json
|
|
317
375
|
{
|
|
318
376
|
"name": "kubectl_delete",
|
|
@@ -327,6 +385,7 @@ Use `kubectl_delete` with field selectors to delete pods in problematic states:
|
|
|
327
385
|
```
|
|
328
386
|
|
|
329
387
|
**Delete completed pods:**
|
|
388
|
+
|
|
330
389
|
```json
|
|
331
390
|
{
|
|
332
391
|
"name": "kubectl_delete",
|
|
@@ -374,6 +433,7 @@ The `node_management` tool provides comprehensive node management capabilities f
|
|
|
374
433
|
#### Usage Examples
|
|
375
434
|
|
|
376
435
|
**1. List all nodes:**
|
|
436
|
+
|
|
377
437
|
```json
|
|
378
438
|
{
|
|
379
439
|
"name": "node_management",
|
|
@@ -384,6 +444,7 @@ The `node_management` tool provides comprehensive node management capabilities f
|
|
|
384
444
|
```
|
|
385
445
|
|
|
386
446
|
**2. Cordon a node (mark as unschedulable):**
|
|
447
|
+
|
|
387
448
|
```json
|
|
388
449
|
{
|
|
389
450
|
"name": "node_management",
|
|
@@ -395,6 +456,7 @@ The `node_management` tool provides comprehensive node management capabilities f
|
|
|
395
456
|
```
|
|
396
457
|
|
|
397
458
|
**3. Drain a node (dry run first):**
|
|
459
|
+
|
|
398
460
|
```json
|
|
399
461
|
{
|
|
400
462
|
"name": "node_management",
|
|
@@ -407,6 +469,7 @@ The `node_management` tool provides comprehensive node management capabilities f
|
|
|
407
469
|
```
|
|
408
470
|
|
|
409
471
|
**4. Drain a node (with confirmation):**
|
|
472
|
+
|
|
410
473
|
```json
|
|
411
474
|
{
|
|
412
475
|
"name": "node_management",
|
|
@@ -423,6 +486,7 @@ The `node_management` tool provides comprehensive node management capabilities f
|
|
|
423
486
|
```
|
|
424
487
|
|
|
425
488
|
**5. Uncordon a node:**
|
|
489
|
+
|
|
426
490
|
```json
|
|
427
491
|
{
|
|
428
492
|
"name": "node_management",
|
|
@@ -60,21 +60,36 @@ export async function kubectlContext(k8sManager, input) {
|
|
|
60
60
|
});
|
|
61
61
|
// Parse the tabular output from kubectl
|
|
62
62
|
const lines = rawResult.trim().split("\n");
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
63
|
+
const headerLine = lines[0];
|
|
64
|
+
// Find column positions based on header positions
|
|
65
|
+
const currentPos = headerLine.indexOf("CURRENT");
|
|
66
|
+
const namePos = headerLine.indexOf("NAME");
|
|
67
|
+
const clusterPos = headerLine.indexOf("CLUSTER");
|
|
68
|
+
const authInfoPos = headerLine.indexOf("AUTHINFO");
|
|
69
|
+
const namespacePos = headerLine.indexOf("NAMESPACE");
|
|
70
|
+
if (currentPos === -1 || namePos === -1 || clusterPos === -1 || authInfoPos === -1 || namespacePos === -1) {
|
|
71
|
+
throw new McpError(ErrorCode.InvalidParams, "Invalid kubectl output format");
|
|
72
|
+
}
|
|
69
73
|
const contexts = [];
|
|
70
74
|
for (let i = 1; i < lines.length; i++) {
|
|
71
|
-
const
|
|
72
|
-
|
|
75
|
+
const line = lines[i];
|
|
76
|
+
if (line.trim() === "")
|
|
77
|
+
continue; // Skip empty lines
|
|
78
|
+
// Extract fields based on column positions
|
|
79
|
+
const isCurrent = line.substring(currentPos, namePos).trim() === "*";
|
|
80
|
+
const name = line.substring(namePos, clusterPos).trim();
|
|
81
|
+
const cluster = line.substring(clusterPos, authInfoPos).trim();
|
|
82
|
+
const authInfo = namespacePos > 0
|
|
83
|
+
? line.substring(authInfoPos, namespacePos).trim()
|
|
84
|
+
: line.substring(authInfoPos).trim();
|
|
85
|
+
const namespace = namespacePos > 0
|
|
86
|
+
? line.substring(namespacePos).trim() || "default"
|
|
87
|
+
: "default";
|
|
73
88
|
contexts.push({
|
|
74
|
-
name:
|
|
75
|
-
cluster:
|
|
76
|
-
user:
|
|
77
|
-
namespace:
|
|
89
|
+
name: name,
|
|
90
|
+
cluster: cluster,
|
|
91
|
+
user: authInfo,
|
|
92
|
+
namespace: namespace,
|
|
78
93
|
isCurrent: isCurrent,
|
|
79
94
|
});
|
|
80
95
|
}
|