Chaos Mesh MCP服务器
用于混沌网格混沌工程操作的模型上下文协议(MCP)服务器。
此MCP服务器为Claude等AI助手提供了直接访问Chaos Mesh的权限,用于自动化混沌工程和弹性测试。通过自然语言对话创建、管理和验证混沌实验。
特性
混沌类型(24种工具)
- 网络混沌 (4个工具):模拟网络延迟、数据包丢失、分区和损坏
- StressChaos 的 (3个工具):对容器施加CPU和内存压力
- PodChaos (3个工具):杀死Pod、使Pod失效或杀死特定容器
- 混沌 (4个工具):注入I/O延迟、故障、属性更改和数据损坏
- Httpchaos (4个工具):中止连接、注入延迟、替换/修补HTTP内容
- DNSChaos (2个工具):返回指定域的DNS错误或随机IP
- 物理机器混沌 (5个工具):在物理/虚拟机上注入混乱(需要Chaosd)
管理与验证(9个工具)
- 环境验证 (3个工具):检查先决条件,验证组件状态,获取混沌特定要求
- 实验管理 (6个工具):查询状态、列出实验、删除、暂停、恢复、获取事件
测试环境
此软件包已通过以下方式进行了测试和验证:
- 混沌网格:v2.8.0
- Kubernetes:v1.27+(用v1.27.6测试)
- kubectl 的:v1.27.6+
- python: 3.10, 3.11, 3.12
先决条件
在使用此MCP服务器之前,请确保您已:
- kubectl 的 已安装并配置
- Kubernetes集群 可通过kubectl(v1.15+)访问
- 混沌网格 已安装在群集中(建议使用v2.6+)
组件特定要求
- DNSChaos:需要
chaos-dns-serverpod在混沌网格命名空间中运行 - 物理机器混沌:在目标物理/虚拟机上需要Chaosd代理
- 其他混沌类型:只需要标准的Chaos Mesh组件(控制器管理器、守护进程)
小贴士:使用 validate_environment 工具来检查你的设置!
安装
步骤1:安装Chaos Mesh
如果您的集群上尚未安装Chaos Mesh:
# Using Helm (Recommended)
helm repo add chaos-mesh https://charts.chaos-mesh.org
helm install chaos-mesh chaos-mesh/chaos-mesh \
--namespace chaos-mesh \
--create-namespace \
--version 2.8.0
# Verify installation
kubectl get pods -n chaos-mesh
# Should see: chaos-controller-manager, chaos-daemon, chaos-dashboard步骤2:安装MCP服务器
选项1:从GitHub安装(推荐)
pip install git+https://github.com/ernestolee13/chaos-mesh-mcp.git选项2:从源代码安装
git clone https://github.com/ernestolee13/chaos-mesh-mcp.git
cd chaos-mesh-mcp
pip install -e .快速开始
1.配置克劳德桌面
编辑 ~/.config/claude/claude_desktop_config.json (Linux/Mac)或 %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"chaos-mesh": {
"command": "python",
"args": ["-m", "chaos_mesh_mcp.server"]
}
}
}2.重新启动克劳德桌面
重新启动Claude Desktop以加载MCP服务器。
3.验证您的环境
在Claude Desktop中,问:
You: "Validate my Chaos Mesh environment"
Claude: [Checks kubectl, cluster connection, Chaos Mesh installation, and components]4.开始使用混沌工程
对话示例:
You: "Create a network delay of 500ms for pods with label app=api for 2 minutes"
Claude: [Creates NetworkChaos experiment]
You: "Check if DNSChaos is available"
Claude: [Runs check_chaos_type_requirements for dns]
You: "List all active chaos experiments in default namespace"
Claude: [Lists current experiments with their status]建筑
chaos-mesh-mcp/
├── chaos_mesh_mcp/
│ ├── server.py # MCP server main entry point
│ ├── kubectl.py # Kubectl command runner
│ ├── templates.py # YAML template rendering
│ ├── validators.py # Parameter validation
│ └── tools/
│ ├── network.py # NetworkChaos (4 tools)
│ ├── stress.py # StressChaos (3 tools)
│ ├── pod.py # PodChaos (3 tools)
│ ├── io.py # IOChaos (4 tools)
│ ├── http.py # HTTPChaos (4 tools)
│ ├── dns.py # DNSChaos (2 tools)
│ ├── physical.py # PhysicalMachineChaos (5 tools)
│ ├── validation.py # Environment validation (3 tools)
│ └── management.py # Experiment management (6 tools)
├── pyproject.toml # Package metadata
├── LICENSE # MIT License
└── README.md # This file环境验证
该MCP包括全面的环境验证:
validate_environment
├─ Check kubectl availability & version
├─ Check cluster connectivity
├─ Check Chaos Mesh installation
├─ Check CRDs (7 chaos types)
└─ Check components
├─ chaos-controller-manager (required)
├─ chaos-daemon (required)
├─ chaos-dns-server (optional, for DNSChaos)
└─ chaos-dashboard (optional)
check_chaos_type_requirements(chaos_type)
├─ Verify specific CRD installed
├─ Check required components running
└─ Show external requirements (e.g., Chaosd for Physical)故障排除
DNSChaos不工作
# Check if chaos-dns-server is running
kubectl get pods -n chaos-mesh | grep dns
# If not present, install with DNS support:
helm upgrade chaos-mesh chaos-mesh/chaos-mesh --namespace=chaos-mesh --set dnsServer.create=true物理机器混沌不工作
PhysicalMachineChaos需要目标机器上的Chaosd代理:
安装说明
- 在目标计算机上安装Chaosd (物理或虚拟):
wget https://mirrors.chaos-mesh.org/chaosd-latest-linux-amd64.tar.gz
tar -xzf chaosd-latest-linux-amd64.tar.gz
sudo cp chaosd-latest-linux-amd64/chaosd /usr/local/bin/
sudo apt-get install -y stress-ng # Required for CPU/Memory stress- 启动Chaosd服务器:
sudo chaosd server --port 31767- 使用正确的地址格式 (⚠️ 重要):
# ✓ CORRECT - No protocol prefix
await create_physical_stress_cpu(
namespace="default",
address=["192.168.1.100:31767"], # IP:PORT only
duration="60s",
workers=2,
load=80
)
# ✗ WRONG - Including http:// causes HTTPS error
await create_physical_stress_cpu(
namespace="default",
address=["http://192.168.1.100:31767"], # Don't do this!
duration="60s"
)重要说明
- 地址格式:使用
IP:PORT或hostname:PORT没有http://或https://前缀 - Chaosd可以在本地主机上运行这台机器可以给自己注入混乱
- 传输层安全:对于生产环境,请使用HTTPS配置Chaosd(测试时可选)
- 时钟动作:需要
pid针对特定流程的参数
请参阅: Chaosd文件
权限错误
确保您的Kubernetes用户具有适当的RBAC权限:
# Check if you can create chaos experiments
kubectl auth can-i create networkchaos --all-namespaces文档
基于Chaos Mesh官方文档:
可用工具(共33个)
NetworkChaos(4个工具)
create_network_delay-注入网络延迟以模拟慢速连接create_network_loss-模拟不可靠网络的丢包create_network_partition-创建网络分割以测试分裂大脑场景create_network_corrupt-破坏网络数据包以测试数据完整性
StressChaos(3个工具)
create_stress_cpu-施加CPU负载以测试压力下的性能create_stress_memory-应用内存压力来测试OOM场景create_stress_combined-同时施加CPU和内存压力
PodChaos(3个工具)
create_pod_kill-杀死吊舱以测试恢复机制create_pod_failure-在不杀死的情况下使吊舱暂时不可用create_container_kill-杀死Pod中的特定容器
IOChaos(4个工具)
create_io_latency-注入I/O延迟以模拟慢速磁盘create_io_fault-返回文件操作的错误代码(ENOSPC、EIO等)create_io_attr_override-修改文件属性(权限、大小)create_io_mistake-在读/写操作中注入数据损坏
HTTPChaos(4个工具)
create_http_abort-中止HTTP连接以模拟网络故障create_http_delay-在HTTP请求/响应中注入延迟create_http_replace-替换HTTP消息内容(标头、正文)create_http_patch-向HTTP消息添加内容
DNSChaos(2个工具)
create_dns_error-返回指定域模式的DNS错误create_dns_random-返回DNS查询的随机IP地址
Physical MachineChaos(5个工具)
create_physical_stress_cpu-在物理/虚拟机上注入CPU压力create_physical_stress_memory-在物理/虚拟机上注入内存压力create_physical_disk_fill-填充物理/虚拟机上的磁盘空间create_physical_process_kill-终止物理/虚拟机上的进程create_physical_clock_skew-在物理/虚拟机上倾斜系统时钟
环境验证(3个工具)
validate_environment-全面的环境验证(kubectl、集群、Chaos Mesh、CRD、组件)check_chaos_type_requirements-检查特定混沌类型的要求get_chaos_requirements-获取混沌类型的详细要求
实验管理(6个工具)
get_experiment_status-获取混沌实验的详细状态list_active_experiments-列出集群中的所有活动实验delete_experiment-删除混沌实验pause_experiment-暂停跑步实验resume_experiment-恢复暂停的实验get_experiment_events-获取Kubernetes事件以进行调试
许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
贡献
这是混沌特工项目的一部分。欢迎问题和拉取请求!
鸣谢
构建于:
- 混沌网格 -云原生混沌工程平台
- 模型上下文协议(MCP) -人工智能模型上下文管理协议
