Kubeshark MCP Server

官方

通过MCP访问集群范围的L4和L7网络流量、数据包、API及完整负载。

文档

Kubeshark MCP 服务器

Kubeshark MCP(模型上下文协议)服务器使 AI 助手(如 Claude Desktop、Cursor 及其他兼容 MCP 的客户端)能够查询实时 Kubernetes 网络流量。

AI 技能

MCP 提供工具 — AI 技能 则教会代理如何使用它们。 技能将原始的 MCP 能力转化为特定领域的工作流,例如根因分析、流量过滤和取证调查。请参阅 技能 README 了解安装和使用方法。

技能描述
network-rca网络根因分析 — 基于快照的回顾性调查,包含 PCAP 和解析路由
kflKFL2 过滤专家 — 编写、调试和优化跨所有支持协议的流量查询

功能特性

  • L7 API 流量分析:查询 HTTP、gRPC、Redis、Kafka、DNS 事务
  • L4 网络流:查看 TCP/UDP 流及其流量统计
  • 集群管理:启动/停止 Kubeshark 部署(带安全控制)
  • PCAP 快照:创建和导出网络捕获
  • 内置提示词:为常见分析任务预配置的提示词

安装

1. 安装 Kubeshark CLI

# macOS
brew install kubeshark

# Linux
sh <(curl -Ls https://kubeshark.com/install)

# Windows (PowerShell)
choco install kubeshark

或从 GitHub Releases 下载。

2. 配置 Claude Desktop

添加到您的 Claude Desktop 配置中:

macOS~/Library/Application Support/Claude/claude_desktop_config.json Windows%APPDATA%\Claude\claude_desktop_config.json

默认(需要 kubectl 访问权限 / kube 上下文)

{
  "mcpServers": {
    "kubeshark": {
      "command": "kubeshark",
      "args": ["mcp"]
    }
  }
}

使用显式的 kubeconfig 路径:

{
  "mcpServers": {
    "kubeshark": {
      "command": "kubeshark",
      "args": ["mcp", "--kubeconfig", "/path/to/.kube/config"]
    }
  }
}

URL 模式(无需 kubectl)

当机器没有 kubectl 访问权限或 kube 上下文时使用此模式。 直接连接到现有的 Kubeshark 部署:

{
  "mcpServers": {
    "kubeshark": {
      "command": "kubeshark",
      "args": ["mcp", "--url", "https://kubeshark.example.com"]
    }
  }
}

启用破坏性操作

{
  "mcpServers": {
    "kubeshark": {
      "command": "kubeshark",
      "args": ["mcp", "--allow-destructive", "--kubeconfig", "/path/to/.kube/config"]
    }
  }
}

3. 生成配置

使用 CLI 生成配置:

kubeshark mcp --mcp-config --url https://kubeshark.example.com

可用工具

流量分析(所有模式)

工具描述
list_workloads列出具有观测流量的 Pod、服务、命名空间
list_api_calls使用 KFL 过滤查询 L7 API 事务
get_api_call获取特定 API 调用的详细信息
get_api_stats获取聚合的 API 统计信息
list_l4_flows列出 L4(TCP/UDP)网络流
get_l4_flow_summary获取 L4 连接性摘要
list_snapshots列出所有 PCAP 快照
create_snapshot创建新的 PCAP 快照
get_dissection_status检查 L7 协议解析状态
enable_dissection启用 L7 协议解析
disable_dissection禁用 L7 协议解析

集群管理(仅限代理模式)

工具描述需要
check_kubeshark_status检查 Kubeshark 是否正在运行-
start_kubeshark将 Kubeshark 部署到集群--allow-destructive
stop_kubeshark从集群中移除 Kubeshark--allow-destructive

可用提示词

提示词描述
analyze_traffic分析 API 流量模式并识别问题
find_errors查找并总结 API 错误和故障
trace_request追踪请求在微服务中的路径
show_topology显示服务通信拓扑
latency_analysis分析延迟模式并识别慢端点
security_audit审计流量中的安全问题
compare_traffic比较不同时间段的流量模式
debug_connection调试服务间的连接问题

对话示例

User: Show me all HTTP 500 errors in the last hour

Claude: I'll query the API traffic for 500 errors.
[Calling list_api_calls with kfl="http and response.status == 500"]

Found 12 HTTP 500 errors:
1. POST /api/checkout -> payment-service (500)
   Time: 10:23:45 | Latency: 2340ms
...
User: What services are communicating with the database?

Claude: Let me check the L4 flows to the database.
[Calling list_l4_flows with dst_filter="postgres"]

Found 5 services connecting to postgres:5432:
- orders-service: 456KB transferred
- users-service: 123KB transferred
...

CLI 选项

选项描述
--urlKubeshark Hub 的直接 URL
--kubeconfigkubeconfig 文件路径
--allow-destructive启用启动/停止操作
--list-tools列出可用工具并退出
--mcp-config打印 Claude Desktop 配置 JSON

KFL(Kubeshark 过滤语言)

使用 KFL 语法查询流量:

# HTTP requests to a specific path
http and request.path == "/api/users"

# Errors only
response.status >= 400

# Specific source pod
src.pod.name == "frontend-.*"

# Multiple conditions
http and src.namespace == "default" and response.status == 500

MCP 注册表

Kubeshark 在每次发布时自动发布到 MCP 注册表

此目录中的 server.json 是一个参考文件。实际的注册表元数据(版本、SHA256 哈希值)在发布工作流期间自动生成。详情请参阅 .github/workflows/release.yml

链接

许可证

Apache-2.0