模拟块设备故障
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
BlockChaos 介绍
Chaos Mesh 提供 BlockChaos 实验类型,可用于模拟块设备延迟或冻结场景。本文档将介绍如何安装 BlockChaos 实验的依赖项并创建 BlockChaos 实验。
BlockChaos 目前处于早期阶段,其安装和配置体验将持续优化。如发现任何问题,请在 chaos-mesh/chaos-mesh 提交 issue 报告。
BlockChaos 的 freeze 操作会影响使用该块设备的所有进程,而不仅限于目标容器。
安装内核模块
BlockChaos 的 delay 操作依赖于 chaos-driver 内核模块,该实验只能在已安装此模块的机器上注入。目前您需要手动编译安装此模块。
-
使用以下命令下载模块源码:
curl -fsSL -o chaos-driver-v0.2.1.tar.gz https://github.com/chaos-mesh/chaos-driver/archive/refs/tags/v0.2.1.tar.gz -
解压
chaos-driver-v0.2.1.tar.gz文件:tar xvf chaos-driver-v0.2.1.tar.gz -
准备当前内核的头文件:
- CentOS/Fedora 系统使用
yum安装:yum install kernel-devel-$(uname -r) - Ubuntu/Debian 系统使用
apt安装:apt install linux-headers-$(uname -r)
- CentOS/Fedora 系统使用
-
编译模块:
cd chaos-driver-v0.2.1
make driver/chaos_driver.ko -
安装内核模块:
insmod ./driver/chaos_driver.ko
chaos_driver 模块需在每次重启后重新安装。要实现自动加载,可将模块复制到 /lib/modules/$(uname -r)/kernel/drivers 的子目录,运行 depmod -a,然后在 /etc/modules 中添加 chaos_driver。
升级内核后需重新编译该模块。
建议使用 DKMS 或 akmod 实现内核模块的自动编译加载。欢迎通过创建 DKMS/akmod 包并提交至各发行版仓库来帮助我们改进安装体验。
使用 YAML 文件创建实验
-
将实验配置写入 YAML 文件,以下以
block-latency.yaml为例:apiVersion: chaos-mesh.org/v1alpha1
kind: BlockChaos
metadata:
name: hostpath-example-delay
spec:
selector:
labelSelectors:
app: hostpath-example
mode: all
volumeName: hostpath-example
action: delay
delay:
latency: 1s备注仅支持 hostpath 或 localvolume 类型卷。
-
使用
kubectl创建实验:kubectl apply -f block-latency.yaml
您将观察到以下变化:
-
卷的 I/O 调度器将切换为
ioem或ioem-mq,可通过cat /sys/block/<device>/queue/scheduler验证。 -
ioem或ioem-mq调度器将接收延迟请求,并将请求延迟指定的时间。
YAML 配置文件中的字段如下表所述:
| Parameter | Type | Note | Default value | Required | Example |
|---|---|---|---|---|---|
mode | string | Specifies the mode of the experiment. The mode options include one (selecting a random Pod), all (selecting all eligible Pods), fixed (selecting a specified number of eligible Pods), fixed-percent (selecting a specified percentage of Pods from the eligible Pods), and random-max-percent (selecting the maximum percentage of Pods from the eligible Pods). | None | Yes | one |
value | string | Provides parameters for the mode configuration, depending on mode. For example, when mode is set to fixed-percent, value specifies the percentage of Pods. | None | No | 1 |
selector | struct | Specifies the target Pod. For details, refer to Define the experiment scope. | None | Yes | |
volumeName | string | Specifies the volume to inject in the target pods. There should be a corresponding entry in the pods' .spec.volumes. | None | Yes | hostpath-example |
action | string | Indicates the specific type of faults. The available fault types include delay and freeze. delay will simulate the latency of block devices, and freeze will simulate that the block device cannot handle any requests | None | Yes | delay |
delay.latency | string | Specifies the latency of the block device. | None | Yes (if action is delay) | 500ms |