Skip to main content
Glama

Kubernetes MCP 服务器

Kubernetes 模型上下文协议 (MCP) 服务器,提供通过标准化接口与 Kubernetes 集群交互的工具。

特征

  • API 资源发现:获取 Kubernetes 集群中所有可用的 API 资源

  • 资源列表:列出任何类型的资源,并提供可选的命名空间和标签过滤

  • 资源详情:获取特定 Kubernetes 资源的详细信息

  • 资源描述:获取 Kubernetes 资源的全面描述

  • Pod Logs :从特定 Pod 检索日志

  • 节点指标:获取特定节点的资源使用情况指标

  • Pod 指标:获取特定 Pod 的 CPU 和内存指标

  • 事件列表:列出命名空间内或特定资源的事件。

  • 资源创建:从清单创建新的 Kubernetes 资源。

  • 标准化接口:使用 MCP 协议实现一致的工具交互

  • 灵活配置:支持不同的 Kubernetes 上下文和资源范围

Related MCP server: Multi Cluster Kubernetes MCP Server

先决条件

  • Go 1.20 或更高版本

  • 访问 Kubernetes 集群

  • 配置了适当集群访问权限的kubectl

安装

  1. 克隆存储库:

git clone https://github.com/reza-gholizade/k8s-mcp-server.git
cd k8s-mcp-server
  1. 安装依赖项:

go mod download
  1. 构建服务器:

go build -o k8s-mcp-server main.go

用法

启动服务器

运行服务器:

./k8s-mcp-server

服务器将启动并在 stdin/stdout 上监听 MCP 协议消息。

可用工具

1. getAPIResources

检索 Kubernetes 集群中所有可用的 API 资源。

参数:

  • includeNamespaceScoped (布尔值):是否包含命名空间范围的资源(默认为 true)

  • includeClusterScoped (布尔值):是否包含集群范围的资源(默认为 true)

例子:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getAPIResources",
  "params": {
    "arguments": {
      "includeNamespaceScoped": true,
      "includeClusterScoped": true
    }
  }
}

2. listResources

列出特定资源类型的所有实例。

参数:

  • Kind (字符串,必需):要列出的资源类型(例如“Pod”、“Deployment”)

  • namespace (字符串):列出资源的命名空间(如果省略,则列出所有命名空间的命名空间资源)

  • labelSelector (字符串):通过标签选择器过滤资源

例子:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "listResources",
  "params": {
    "arguments": {
      "Kind": "Pod",
      "namespace": "default",
      "labelSelector": "app=nginx"
    }
  }
}

3. getResource

检索有关特定资源的详细信息。

参数:

  • kind (字符串,必需):要获取的资源类型(例如,“Pod”,“Deployment”)

  • name (字符串,必需):要获取的资源的名称

  • namespace (字符串):资源的命名空间(如果它是命名空间资源)

例子:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getResource",
  "params": {
    "arguments": {
      "kind": "Pod",
      "name": "nginx-pod",
      "namespace": "default"
    }
  }
}

4. describeResource

根据给定的种类和名称描述 Kubernetes 集群中的资源,类似于kubectl describe

参数:

  • Kind (字符串,必需):要描述的资源类型(例如“Pod”、“Deployment”)

  • name (字符串,必需):要描述的资源的名称

  • namespace (字符串):资源的命名空间(如果它是命名空间资源)

例子:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "describeResource",
  "params": {
    "arguments": {
      "Kind": "Pod",
      "name": "nginx-pod",
      "namespace": "default"
    }
  }
}

5. getPodsLogs

检索 Kubernetes 集群中特定 pod 的日志。

参数:

  • Name (字符串,必需):要从中获取日志的 pod 的名称。

  • namespace (字符串):pod 的命名空间(如果它是命名空间资源)。

例子:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getPodsLogs",
  "params": {
    "arguments": {
      "Name": "my-app-pod-12345",
      "namespace": "production"
    }
  }
}

6. getNodeMetrics

检索 Kubernetes 集群中特定节点的资源使用情况指标。

参数:

  • Name (字符串,必需):要从中获取指标的节点的名称。

例子:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getNodeMetrics",
  "params": {
    "arguments": {
      "Name": "worker-node-1"
    }
  }
}

7. getPodMetrics

检索 Kubernetes 集群中特定 pod 的 CPU 和内存指标。

参数:

  • namespace (字符串,必需):pod 的命名空间。

  • podName (字符串,必需):pod 的名称。

例子:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getPodMetrics",
  "params": {
    "arguments": {
      "namespace": "default",
      "podName": "my-app-pod-67890"
    }
  }
}

8. getEvents

检索 Kubernetes 集群中特定命名空间或资源的事件。

参数:

  • namespace (字符串):用于获取事件的命名空间。如果省略,则所有命名空间的事件都会被考虑(前提是 RBAC 允许)。

  • resourceName (字符串):用于过滤事件的特定资源的名称(例如,Pod 名称)。

  • resourceKind (字符串):如果提供了resourceName ,则为特定资源的种类(例如“Pod”)。

示例(命名空间事件):

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getEvents",
  "params": {
    "arguments": {
      "namespace": "default"
    }
  }
}

示例(资源事件):

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getEvents",
  "params": {
    "arguments": {
      "namespace": "production",
      "resourceName": "my-app-pod-12345",
      "resourceKind": "Pod"
    }
  }
}

9. createorUpdateResource

从 YAML 或 JSON 清单在 Kubernetes 集群中创建新资源。

参数:

  • manifest (字符串,必需):要创建的资源的 YAML 或 JSON 清单。

  • namespace (字符串,可选):创建资源时所用的命名空间。如果清单中包含命名空间,则可以省略此参数或使用它来覆盖它(具体行为可能取决于服务器实现)。

例子:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "createResource",
  "params": {
    "arguments": {
      "namespace": "default",
      "manifest": "apiVersion: v1\nkind: Pod\nmetadata:\n  name: my-new-pod\nspec:\n  containers:\n  - name: nginx\n    image: nginx:latest"
    }
  }
}

发展

项目结构

.
├── handlers/         # Tool handlers
│   └── handlers.go   # Implementation of MCP tools
├── pkg/             # Internal packages
│   └── k8s/         # Kubernetes client implementation
├── main.go          # Server entry point
├── go.mod           # Go module definition
└── go.sum           # Go module checksums

添加新工具

要添加新工具:

  1. handlers/handlers.go中创建一个新的工具定义函数(例如MyNewTool() mcp.Tool

  2. handlers/handlers.go中实现工具处理函数(例如, MyNewHandler(client *k8s.Client) func(...)

  3. 使用s.AddTool()main.go中注册该工具及其处理程序

贡献

欢迎贡献!请参阅CONTRIBUTING.md了解如何为此项目做出贡献的详细信息。

执照

gholizade.net@gmail.com

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。

A
license - permissive license
Not graded
quality - not tested
A
maintenance

Maintenance

Maintainers
14hResponse time
5wRelease cycle
9Releases (12mo)
Commit activity
Issues opened vs closed

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    A Model Context Protocol server that enables AI assistants to interact with Kubernetes clusters through natural language, supporting core Kubernetes operations, monitoring, security, and diagnostics.
    115
    947
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    An MCP server that enables interaction with multiple Kubernetes clusters simultaneously, providing comprehensive tools for cluster management, resource operations, and diagnostics across different environments.
  • A
    license
    Not graded
    quality
    D
    maintenance
    A Model Context Protocol server for Kubernetes that provides full resource coverage and advanced troubleshooting tools via HTTP chunked streaming. It enables users to manage clusters and diagnose complex issues like pod crashloops through specialized prompts and standard kubectl-like operations.
    12,374
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    An MCP server for generating Kubernetes manifests (deployments, services, configmaps, secrets, ingresses, namespaces) and performing kubectl operations like apply, delete, get, describe, logs, and exec.
    MIT

View all related MCP servers

Related MCP Connectors

  • An MCP server that let you interact with Cycloid.io Internal Development Portal and Platform

  • A MCP server built for developers enabling Git based project management with project and personal…

  • MCP server for InsForge BaaS — database, storage, edge functions, and deployments

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/reza-gholizade/k8s-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server