Kubernetes管理控制协议

一个通过自然语言管理Kubernetes集群的工具,提供25种Kubernetes操作工具、多集群支持、高级RBAC和企业级安全功能。

  • by achetronic
  • Go
  • 本地部署
  • 42 星标
  • 更新于
在 GitHub 查看 achetronic/kubernetes-mcp

使用说明

为什么选择Kubernetes MCP?

AI助手功能强大,但它们在Kubernetes上很难使用,因为:

  • 上下文窗口限制:单身 kubectl get pods -A 可能会超出您的代币预算
  • 安全问题:你不希望AI删除你的生产数据库
  • 多集群复杂性:在集群之间跳转容易出错

特性

🎯 25 Kubernetes Tools

通过自然语言进行全面集群管理:

类别 工具
阅读 get_resource, list_resources, describe_resource
修改 apply_manifest, patch_resource, delete_resource, delete_resources
规模和推出 scale_resource, get_rollout_status, restart_rollout, undo_rollout
调试 get_logs, exec_command, list_events
集群信息 get_cluster_info, list_api_resources, list_api_versions, list_namespaces
上下文 get_current_context, list_contexts, switch_context
RBAC和指标 check_permission, get_pod_metrics, get_node_metrics
差异 diff_manifest

所有资源寻址工具都需要 谷歌虚拟现实 参数: group + version + resource (复数小写形式,例如。 pods, deployments, ingresses, storageclasses).不是那种。两个清单工具(apply_manifest, diff_manifest)解析 apiVersion/kind 从YAML,并通过集群的发现API解决GVR,因此CRD和不规则复数透明地工作。

内置安全栏杆:

  • apply_manifest 拒绝多文档YAML和报告 created vs updated.
  • delete_resources 需要 namespace 或明确 all_namespaces=true (互斥),并拒绝删除超过 kubernetes.tools.bulk_operations.max_resources_per_operation 每次呼叫的项目数(默认值为100)。
  • get_logs 将输出截断为1 MiB; exec_command 非交互式,支持可配置 timeout_seconds (1..300,默认值30),并将stdout+stderr限制在1 MiB。
  • restart_rollout / undo_rollout 仅在以下情况下操作 apps/{deployments,statefulsets,daemonsets}; undo_rollout 默认为N-1(kubectl兼容),并读取StatefulSets和DaemonSets的Deployment/ControllerRevisions的ReplicaSet历史记录。
🔍 Context-Window-Friendly Filtering

所有工具支持 yq表达式 在响应到达您的人工智能之前对其进行过滤。只需自然地问:

“获取我的应用程序部署的映像”

AI自动使用过滤来返回 nginx:1.25 而不是200多行YAML——为重要的事情保存上下文窗口。

复杂的查询也适用:

“列出所有正在运行的Pod及其IP地址”

在幕后,AI会链接多个yq表达式来过滤和转换响应。

🔐 Advanced RBAC

基于规则策略的细粒度访问控制——按以下条件过滤 工具, 上下文, API集团, 资源 (复数GVR), 命名空间,以及 资源名称拒绝总是赢,默认拒绝,全球全力支持。看 授权 详细信息和示例。

🌐 Multi-Cluster Support

使用独立配置管理多个集群:

kubernetes:
  default_context: "staging"
  contexts:
    - name: "production"
      kubeconfig: "/etc/kubernetes/prod.kubeconfig"
      description: "Production - handle with care"
      denied_namespaces: ["kube-system", "istio-system"]

    - name: "staging"
      kubeconfig: "/etc/kubernetes/staging.kubeconfig"
      description: "Staging - safe for testing"

    - name: "development"
      kubeconfig: "/etc/kubernetes/dev.kubeconfig"
      description: "Development - experiment freely"

  # Or auto-load from directory (context name = current-context of each file)
  contexts_dir: "/etc/kubernetes/clusters/"

热重载:Kubeconfig文件会被监视是否有更改。当sidecar或外部进程更新kubeconfig时,客户端会自动重新加载,无需重新启动。

🛡️ Enterprise-Ready Security
  • 符合OAuth 2.1标准 具有RFC 8414和RFC 9728端点
  • JWT验证 基于JWKS和CEL的索赔条件
  • API密钥验证 具有静态令牌和可配置的有效载荷
  • 命名空间允许/拒绝列表 每个集群
  • 访问日志 带有标题编辑功能

快速开始

选项1:克劳德桌面(本地二进制)

1.下载二进制文件:

# Linux
curl -L https://github.com/achetronic/kubernetes-mcp/releases/latest/download/kubernetes-mcp-linux-amd64.tar.gz | tar xz

# macOS (Intel)
curl -L https://github.com/achetronic/kubernetes-mcp/releases/latest/download/kubernetes-mcp-darwin-amd64.tar.gz | tar xz

# macOS (Apple Silicon)
curl -L https://github.com/achetronic/kubernetes-mcp/releases/latest/download/kubernetes-mcp-darwin-arm64.tar.gz | tar xz

2.创建配置文件:

# ~/.config/kubernetes-mcp/config.yaml
server:
  name: "Kubernetes MCP"
  version: "0.1.0"
  transport:
    type: "stdio"

middleware:
  jwt:
    enabled: false

kubernetes:
  default_context: "default"
  contexts:
    - name: "default"
      kubeconfig: "" # Empty: $KUBECONFIG -> ~/.kube/config -> in-cluster
      description: "Local cluster"
  discovery:
    refresh_interval: "10m"

authorization:
  allow_anonymous: true
  policies:
    - name: "allow-all"
      match:
        expression: "true"
      rules:
        - effect: allow
          tools: ["*"]
          contexts: ["*"]
          resources:
            - groups: ["*"]
              resources: ["*"]
            - groups: ["_"]
              resources: ["*"]

3.配置克劳德桌面:

编辑 claude_desktop_config.json:

{
  "mcpServers": {
    "kubernetes": {
      "command": "/path/to/kubernetes-mcp",
      "args": ["--config", "/path/to/config.yaml"]
    }
  }
}

4.重新启动克劳德桌面 开始管理你的集群!


选项2:Docker

1.创建配置文件:

# config.yaml
server:
  name: "Kubernetes MCP"
  version: "0.1.0"
  transport:
    type: "http"
    http:
      host: ":8080"

middleware:
  jwt:
    enabled: false

kubernetes:
  default_context: "default"
  contexts:
    - name: "default"
      kubeconfig: "/root/.kube/config"
      description: "My Kubernetes cluster"
  discovery:
    refresh_interval: "10m"

authorization:
  allow_anonymous: true
  policies:
    - name: "allow-all"
      match:
        expression: "true"
      rules:
        - effect: allow
          tools: ["*"]
          contexts: ["*"]
          resources:
            - groups: ["*"]
              resources: ["*"]
            - groups: ["_"]
              resources: ["*"]

2.使用Docker运行:

docker run -d \
  --name kubernetes-mcp \
  -p 8080:8080 \
  -v ~/.kube/config:/root/.kube/config:ro \
  -v $(pwd)/config.yaml:/config.yaml:ro \
  ghcr.io/achetronic/kubernetes-mcp:latest \
  --config /config.yaml

3.测试:

MCP服务器公开以下协议 /mcp (POST、JSON-RPC)和OAuth 发现下 /.well-known/oauth-* 当这些功能被激活时。没有 朴素 /health 终点;通过发出MCP验证服务器是否已启动 initialize 握手:

curl -s -X POST http://localhost:8080/mcp \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"smoke","version":"0"}}}'

A. 200 响应a serverInfo block表示服务器已启动 谈论MCP。该回复还包括 Mcp-Session-Id 标题那 客户端在后续请求中传播。


选项3:带有Helm的Kubernetes

我们使用 Bjw-s/app寺庙 directly——一种流行的通用Helm图表,避免了重新发明轮子。不需要包装图表。

# Add the bjw-s repository
helm repo add bjw-s https://bjw-s-labs.github.io/helm-charts
helm repo update

# Download our values file and install
curl -LO https://raw.githubusercontent.com/achetronic/kubernetes-mcp/master/chart/values.yaml
helm install kubernetes-mcp bjw-s/app-template --version 4.2.0 \
  -f values.yaml -n kubernetes-mcp --create-namespace

编辑 values.yaml 配置您的环境。看 图表/值.yaml 对于所有选项。

集群内凭据和RBAC

在集群内运行时,离开 kubeconfig: "" 在您的配置和 服务器将无法访问Pod的ServiceAccount令牌 (/var/run/secrets/kubernetes.io/serviceaccount).图表值确实 不 发布默认的ClusterRoleBinding——您可以决定服务器是什么 允许在Kubernetes RBAC级别执行。一个最小的“顺其自然” 将“一切”示例放入您的清单中:

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: kubernetes-mcp
  namespace: kubernetes-mcp
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: kubernetes-mcp
rules:
  - apiGroups: ["*"]
    resources: ["*"]
    verbs: ["*"]
  - nonResourceURLs: ["*"]
    verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: kubernetes-mcp
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: kubernetes-mcp
subjects:
  - kind: ServiceAccount
    name: kubernetes-mcp
    namespace: kubernetes-mcp

这相当于 cluster-admin 对于服务帐户。限制 在将服务器暴露在可信网络之外之前,规则会阻止。这 MCP授权层(CEL策略)独立于集群的 RBAC,首先检查;两层都必须允许呼叫到达 API服务器。


配置参考

完整示例

# MCP Server Configuration
server:
  name: "Kubernetes MCP"
  version: "0.1.0"
  transport:
    type: "http" # or "stdio"
    http:
      host: ":8080"

# Middleware Configuration
middleware:
  access_logs:
    excluded_headers:
      - X-Request-Id
    redacted_headers:
      - Authorization

  jwt:
    enabled: true
    validation:
      jwks_uri: "https://keycloak.example.com/realms/mcp/protocol/openid-connect/certs"
      cache_interval: "10s"
      allow_conditions:
        - expression: "has(payload.email)"

  api_keys:
    enabled: true
    keys:
      - name: "ci-cd-pipeline"
        token: "$CI_API_KEY"
        payload:
          sub: "ci-cd-service"
          email: "ci@company.com"
          groups:
            - "ci-cd"

# OAuth Configuration (optional, for remote clients)
oauth_authorization_server:
  enabled: true
  issuer_uri: "https://keycloak.example.com/realms/mcp"

oauth_protected_resource:
  enabled: true
  resource: "https://kubernetes-mcp.example.com/mcp"
  auth_servers:
    - "https://keycloak.example.com/realms/mcp"
  scopes_supported: [openid, profile, email, groups]

# Kubernetes Configuration
kubernetes:
  default_context: "production"
  
  # Explicit contexts with custom names
  contexts:
    - name: "production"
      kubeconfig: "/etc/kubernetes/prod.kubeconfig"
      kubeconfig_context: "gke_myproject_prod"  # Optional: use specific context from kubeconfig
      description: "Production cluster"
      allowed_namespaces: [] # Empty = all allowed
      denied_namespaces:
        - kube-system
        - kube-public
        - istio-system

    - name: "staging"
      kubeconfig: "/etc/kubernetes/staging.kubeconfig"
      description: "Staging cluster"

  # Auto-load kubeconfigs from directory (context name = current-context of each file)
  # contexts_dir: "/etc/kubernetes/clusters/"

  # API discovery cache. The RESTMapper uses it to translate Kind <-> Resource
  # for 'apply_manifest' / 'diff_manifest', to resolve the Kind in
  # 'describe_resource' (used to filter related events) and to surface newly
  # installed CRDs. The cache is invalidated on this interval. Default: 10m.
  discovery:
    refresh_interval: "10m"

  tools:
    bulk_operations:
      # Hard cap on the number of resources delete_resources may match in a
      # single call. Selectors that match more are rejected. Default: 100.
      max_resources_per_operation: 100

# Authorization Configuration
authorization:
  allow_anonymous: false
  policies:
    - name: "sre-full-access"
      description: "SRE team has full access"
      match:
        expression: 'payload.groups.exists(g, g == "sre-team")'
      rules:
        - effect: allow
          tools: ["*"]
          contexts: ["*"]
          resources:
            - groups: ["*"]
              resources: ["*"]
            - groups: ["_"]
              resources: ["*"]

    - name: "developers-limited"
      description: "Developers: full in staging, read-only in prod"
      match:
        expression: 'payload.groups.exists(g, g == "developers")'
      rules:
        - effect: allow
          tools: ["*"]
          contexts: ["staging"]
          resources:
            - groups: ["*"]
              resources: ["*"]
        - effect: deny
          tools: ["delete_resource", "delete_resources", "exec_command"]
          contexts: ["production"]

环境变量

所有配置值都支持加载时的环境变量扩展 ($VAR 或 ${VAR}):

kubernetes:
  contexts:
    - name: "production"
      kubeconfig: "$PROD_KUBECONFIG"   # Expanded at runtime

认证

Kubernetes MCP支持两种身份验证方法。两者都生产相同的产品 payload 使用的地图 通过授权策略,因此RBAC规则无论采用何种方法都能以相同的方式工作。

JWT验证

根据JWKS端点验证承载令牌。JWT的索赔成为 payload 可用CEL表达式表示。

middleware:
  jwt:
    enabled: true
    validation:
      jwks_uri: "https://keycloak.example.com/realms/mcp/protocol/openid-connect/certs"
      cache_interval: "10s"
      allow_conditions:
        - expression: 'has(payload.email)'
字段 描述
jwks_uri 用于签名验证的JWKS端点的URL
cache_interval 多久刷新一次JWKS键
allow_conditions 必须全部计算为的CEL表达式 true JWT被接受

API密钥验证

具有预配置的静态承载令牌 payload可用于CI/CD管道、服务帐户、, 或者身份提供者不可用的环境。

middleware:
  api_keys:
    enabled: true
    keys:
      - name: "ci-cd-pipeline"
        token: "$CI_API_KEY"
        payload:
          sub: "ci-cd-service"
          email: "ci@company.com"
          groups:
            - "ci-cd"

      - name: "monitoring"
        token: "$MONITORING_API_KEY"
        payload:
          sub: "monitoring-agent"
          groups:
            - "readonly"
字段 描述
name 密钥的人类可读标识符(用于日志)
token Bearer令牌值。支持环境变量扩展
payload 作为RBAC评估的身份验证有效载荷注入的字段映射

安全:使用恒定时间比较(启动时哈希SHA-256)对令牌进行比较 以防止定时攻击。使用环境变量($CI_API_KEY)而不是硬编码令牌。

组合使用

当这两种方法都启用时,中间件链会首先尝试JWT。如果令牌不是有效的JWT, 它落到API密钥匹配。如果两者都不成功,则请求将在未经身份验证的情况下继续进行 (默认情况下拒绝,除非 allow_anonymous: true).

授权策略评估

  1. 如果没有有效载荷且不允许匿名→ 否认
  2. 找到 全部 其政策 match CEL表达式为真
  3. 收集 所有规则 从匹配的政策到单一列表
  4. 如果 任何拒绝规则 匹配请求→ 否认 (否认总是赢)
  5. 如果 任何允许规则 匹配请求→ 允许
  6. 违约: 否认

拒绝优先:拒绝规则总是覆盖允许规则,无论它来自哪个策略。从所有允许规则中省略工具也会拒绝它(默认拒绝)。

资源级别授权

通过以下方式控制访问 API集团, 资源 (复数小写GVR), 命名空间,以及 名字.

参考

字段 示例 省略时的行为
groups [""] (核心), ["apps"], ["_"] (虚拟) 任何组
versions ["v1"], ["v1beta1"] 任何版本
resources ["pods", "secrets"] 任何资源
namespaces ["default"], ["team-*"], [""] (集群范围) 任何命名空间+集群范围
names ["myapp-*"], ["*-config"] 任何名字

小贴士:资源使用与Kubernetes GVR匹配的复数小写形式(例如。 pods, deployments, configmaps).省略 versions 除非您需要特定的API版本。

通配符

模式 含义
* 全部匹配
prefix-* 开始于
*-suffix 结束于

示例:允许除敏感资源之外的所有内容

- name: "all-except-sensitive"
  match:
    expression: "true"
  rules:
    - effect: allow
      tools: ["*"]
      contexts: ["*"]
      resources:
        - groups: ["*"]
          resources: ["*"]
        - groups: ["_"]
          resources: ["*"]
    - effect: deny
      resources:
        - groups: [""]
          resources: ["secrets"]
        - groups: ["rbac.authorization.k8s.io"]
          resources: ["*"]
        - groups: ["certificates.k8s.io"]
          resources: ["*"]
        - groups: ["*"]
          resources: ["*"]
          namespaces: ["kube-system", "kube-public"]

示例:阻止秘密

- name: "no-secrets"
  match:
    expression: "true"
  rules:
    - effect: allow
      tools: ["*"]
      contexts: ["*"]
      resources:
        - groups: ["*"]
          resources: ["*"]
    - effect: deny
      resources:
        - groups: [""]
          resources: ["secrets"]

示例:只读,无敏感资源

- name: "read-only-safe"
  match:
    expression: '"developers" in payload.groups'
  rules:
    - effect: allow
      tools: ["get_resource", "list_resources", "describe_resource", "get_logs"]
      contexts: ["*"]
      resources:
        - groups: ["", "apps", "batch", "networking.k8s.io"]
          resources: ["*"]
    - effect: deny
      tools: ["get_*", "list_*", "describe_*"]
      resources:
        - groups: [""]
          resources: ["secrets"]
        - groups: ["rbac.authorization.k8s.io"]
          resources: ["*"]

示例:仅在团队命名空间中写入

- name: "write-own-namespaces"
  match:
    expression: '"developers" in payload.groups'
  rules:
    - effect: allow
      tools: ["apply_manifest", "patch_resource", "delete_resource"]
      contexts: ["staging"]
      resources:
        - groups: ["", "apps"]
          resources: ["*"]
          namespaces: ["team-*"]
    - effect: deny
      resources:
        - groups: [""]
          resources: ["secrets"]

示例:CI/CD服务帐户

- name: "cicd-deploy"
  match:
    expression: 'payload.client_id == "ci-cd-service"'
  rules:
    - effect: allow
      tools: ["apply_manifest", "diff_manifest", "get_resource"]
      contexts: ["production"]
      resources:
        - groups: ["", "apps"]
          resources: ["deployments", "services", "configmaps"]
          namespaces: ["app-*"]

示例:完全管理员权限

- name: "sre-full-access"
  match:
    expression: '"sre" in payload.groups'
  rules:
    - effect: allow
      tools: ["*"]
      contexts: ["*"]
      resources:
        - groups: ["*"]
          resources: ["*"]
        - groups: ["_"]
          resources: ["*"]

示例:安全操作(读取+选择性删除)

安全生产政策。允许规则包括读取、差异、缩放、展开 以及吊舱日志。 delete_resource 仅允许用于吊舱 aplicacion-* 命名空间(以及 default).任何未在任何允许中列出的内容 默认情况下,规则被拒绝,包括 apply_manifest, patch_resource 和 delete_resources.拒绝规则进一步缩小了允许范围:阅读 机密、服务帐户和各种机密管理CRD 禁止,以及 exec_command 被彻底封锁了。

- name: "safe-operations"
  match:
    expression: 'has(payload.sub)'
  rules:
    - effect: allow
      tools: ["get_*", "list_*", "describe_*", "diff_*", "check_*", "scale_*", "*_rollout*", "get_logs"]
      contexts: ["*"]
      resources:
        - groups: ["*"]
          resources: ["*"]
        - groups: ["_"]
          resources: ["*"]
    - effect: allow
      tools: ["delete_resource"]
      resources:
        - groups: [""]
          resources: ["pods"]
          namespaces: ["aplicacion-*", "default"]
    - effect: deny
      tools: ["get_*", "list_*", "describe_*"]
      resources:
        - groups: [""]
          resources: ["secrets", "serviceaccounts"]
        - groups: ["external-secrets.io", "cert-manager.io", "certificates.k8s.io"]
          resources: ["*"]
    - effect: deny
      tools: ["exec_command"]

虚拟MCP资源

不在K8s资源上运行的工具使用组下的虚拟资源 _:

工具 资源
list_api_resources, list_api_versions apidiscovery
get_cluster_info clusterinfo
get_current_context, list_contexts, switch_context contexts
# Allow discovery and context switching
resources:
  - groups: ["_"]
    resources: ["apidiscovery", "clusterinfo", "contexts"]

用法示例

问你的AI助手:

"List all pods in the production namespace that are not running"

AI将使用:

tool: list_resources
version: v1
resource: pods       # plural lowercase GVR, NOT the Kind
namespace: production
yq_expressions:
  - '.items[] | select(.status.phase != "Running") | {name: .metadata.name, phase: .status.phase}'

更多示例:

请求 使用的工具
“在舞台上使用最多内存的是什么?” get_pod_metrics 使用yq排序
“重新启动api部署” restart_rollout
“如果我将映像更改为nginx:1.26,请显示差异” diff_manifest
“将工作人员扩展到5个副本” scale_resource
“为什么支付舱失败了?” describe_resource + get_logs
“切换到开发集群” switch_context

发展

先决条件

  • 转到1.25+
  • 访问Kubernetes集群
  • (可选)用于构建镜像的Docker

构建与运行

# Build binary
make build

# Run with HTTP transport
make run

# Run with custom config
./bin/kubernetes-mcp-linux-amd64 --config /path/to/config.yaml

项目结构

kubernetes-mcp/
├── cmd/main.go                    # Entrypoint
├── api/config_types.go            # Configuration types
├── internal/
│   ├── k8stools/                  # MCP tools implementation
│   │   ├── manager.go             # Tool registration
│   │   ├── helpers.go             # Shared utilities
│   │   ├── tools_read.go          # get_resource, list_resources, describe_resource
│   │   ├── tools_modify.go        # apply, patch, delete
│   │   ├── tools_scale_rollout.go # scale, rollout operations
│   │   ├── tools_logs_exec.go     # logs, exec, events
│   │   ├── tools_cluster.go       # cluster info, namespaces, api resources
│   │   ├── tools_context.go       # context management
│   │   ├── tools_rbac_metrics.go  # permissions, metrics
│   │   ├── tools_diff.go          # manifest diff
│   │   └── e2e_*_test.go          # End-to-end tests (build tag 'e2e')
│   ├── kubernetes/client.go       # Multi-cluster client manager
│   ├── authorization/evaluator.go # RBAC evaluator
│   ├── yqutil/evaluator.go        # yq expression processor
│   ├── middlewares/               # Auth, JWT, API key, logging middlewares
│   └── handlers/                  # OAuth endpoints
├── docs/
│   ├── config-http.yaml           # HTTP mode example
│   └── config-stdio.yaml          # Stdio mode example
├── chart/                         # Helm values for bjw-s/app-template
├── .agents/                       # Internal architecture & design docs
└── .github/workflows/             # CI: release-binaries, release-docker-images, e2e-tests

添加新工具

  1. 在中创建处理程序 internal/k8stools/tools_<category>.go:
func (m *Manager) registerMyTool() {
    tool := mcp.NewTool("my_tool",
        mcp.WithDescription("Does something useful"),
        mcp.WithString("param", mcp.Required(), mcp.Description("A parameter")),
    )
    m.mcpServer.AddTool(tool, m.handleMyTool)
}

func (m *Manager) handleMyTool(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
    args := request.GetArguments()
    // ... implementation
    return successResult("Done!"), nil
}
  1. 注册于 manager.go:
func (m *Manager) RegisterAll() {
    // ... existing tools
    m.registerMyTool()
}

运行测试

# Format and vet
make fmt
make vet

# Lint (auto-installs golangci-lint)
make lint

# Unit tests (no cluster needed)
make test

# End-to-end tests against a Kind cluster
#   - 'kind-up'       creates a local Kind cluster (idempotent)
#   - 'test-e2e'      runs the e2e suite (build tag 'e2e')
#   - 'kind-down'     deletes the cluster
#   - 'test-e2e-clean' = down + up + tests + down (CI-style)
make test-e2e
make test-e2e-clean

# Run e2e against an existing cluster (no Kind dance)
KMCP_E2E_CONTEXT=$(kubectl config current-context) \
  go test -tags=e2e -timeout 10m ./internal/k8stools/...

端到端测试

e2e套房位于 internal/k8stools/e2e_*_test.go (构建标签 e2e).它针对一个真实的集群练习每个工具,每个测试都在自己的一次性命名空间中运行。保险范围包括:

区域 亮点
阅读 get_resource, list_resources 过滤器, describe_resource 通过RESTMapper解决事件
修改 apply_manifest 创建/更新往返保留 Service.clusterIP、多文档拒绝、补丁类型、删除+批量上限+跨命名空间屏障
缩放/展开 缩放、展开状态(部署/StatefulSet/DaemonSet)、重新启动、, 撤消所有三种工作负载类型
集群信息 list_namespaces, list_api_resources (组/命名空间过滤器), list_api_versions, get_cluster_info
Logs/exec/events 日志检索和尾部,带输出上限的exec,按时间戳排序并按类型/字段选择器过滤的事件
RBAC/指标 check_permission 包括子资源(pods/exec),指标服务器缺失时的优雅降级
发现 新安装的CRD在以下时间后可见 RESTMapper.Reset()
硬化 空补丁拒绝, replicas 验证, propagation_policy 验证, delete_resources 元件盖, apply_manifest 创建vs更新

集 KMCP_E2E_CONTEXT 指向要使用的kubeconfig上下文(默认为kubeconfig的当前上下文)。当未安装度量服务器时,测试会跳过度量快乐路径。

CI在每个PR上运行相同的套件,并推动 master 通过 .github/workflows/e2e-tests.yaml 使用 helm/kind-action.

构建Docker镜像

make docker-build IMG=your-registry/kubernetes-mcp:tag

文档


贡献

欢迎所有捐款!无论您是报告错误、建议功能还是提交代码——谢谢!


许可证

Kubernetes MCP根据 Apache 2.0许可证.