模拟 Azure 故障
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
本文档介绍如何使用 Chaos Mesh 模拟 Azure 故障。
AzureChaos 介绍
AzureChaos 可帮助您在指定的 Azure 实例上模拟故障场景。目前支持的故障类型包括:
-
VM 停止:停止指定的 VM 实例。
-
VM 重启:重启指定的 VM 实例。
-
磁盘卸载:从指定的 VM 实例卸载数据磁盘。
Secret 文件
为方便连接至 Azure 集群,建议预先创建 Kubernetes Secret 文件存储认证信息。
Secret 文件示例如下:
apiVersion: v1
kind: Secret
metadata:
name: cloud-key-secret
namespace: chaos-mesh
type: Opaque
stringData:
client_id: your-client-id
client_secret: your-client-secret
tenant_id: your-tenant-id
-
name:表示 Kubernetes Secret 对象名称。
-
namespace:表示 Kubernetes Secret 对象所属的命名空间。
-
client_id:存储 Azure 应用注册的应用程序(客户端)ID。
-
client_secret:存储 Azure 应用注册的应用程序(客户端)密钥。
-
tenant_id:存储 Azure 应用注册的目录(租户)ID。有关
client_id和client_secret的详细信息,请参考机密客户端应用程序。
请确保 Secret 文件中的应用注册已被添加为 VM 实例访问控制 (IAM) 的参与者或所有者。
使用 Chaos Dashboard 创建实验
-
打开 Chaos Dashboard,点击页面上的 新建实验 按钮:

img -
在 选择目标 区域,选择 AZURE 故障 并指定具体行为(如 VM 停止)。
-
填写实验信息,指定实验范围和计划持续时间。
-
提交实验信息。
使用 YAML 文件创建实验
vm-stop 配置示例
-
将以下实验配置写入
azurechaos-vm-stop.yaml文件:apiVersion: chaos-mesh.org/v1alpha1
kind: AzureChaos
metadata:
name: vm-stop-example
namespace: chaos-mesh
spec:
action: vm-stop
secretName: 'cloud-key-secret'
subscriptionID: 'your-subscription-id'
resourceGroupName: 'your-resource-group-name'
vmName: 'your-vm-name'
duration: '5m'此配置将使 Chaos Mesh 向指定 VM 实例注入
vm-stop故障,导致该实例在 5 分钟内不可用。有关停止 VM 实例的更多信息,请参阅 Azure 文档 - 启动或停止 VM。
-
配置文件准备完成后,使用
kubectl创建实验:kubectl apply -f azurechaos-vm-stop.yaml
vm-restart 配置示例
-
将实验配置写入
azurechaos-vm-restart.yaml文件:apiVersion: chaos-mesh.org/v1alpha1
kind: AzureChaos
metadata:
name: vm-restart-example
namespace: chaos-mesh
spec:
action: vm-restart
secretName: 'cloud-key-secret'
subscriptionID: 'your-subscription-id'
resourceGroupName: 'your-resource-group-name'
vmName: 'your-vm-name'根据此配置示例,Chaos Mesh 将向指定 VM 实例注入
vm-restart故障,导致该 VM 实例重启。有关重启 VM 实例的更多信息,请参阅 Azure 文档 - 重启 VM。
-
配置文件准备就绪后,使用
kubectl创建实验:kubectl apply -f azurechaos-vm-restart.yaml
detach-volume 配置示例
-
将实验配置写入
azurechaos-disk-detach.yaml文件:apiVersion: chaos-mesh.org/v1alpha1
kind: AzureChaos
metadata:
name: disk-detach-example
namespace: chaos-mesh
spec:
action: disk-detach
secretName: 'cloud-key-secret'
subscriptionID: 'your-subscription-id'
resourceGroupName: 'your-resource-group-name'
vmName: 'your-vm-name'
diskName: 'your-disk-name'
lun: 'your-disk-lun'
duration: '5m'根据此配置示例,Chaos Mesh 将在 5 分钟内向指定 VM 实例注入
disk-detach故障,使其与指定数据磁盘分离。有关分离 Azure 数据磁盘的更多信息,请参阅 Azure 文档 - 分离数据磁盘。
-
配置文件准备就绪后,使用
kubectl创建实验:kubectl apply -f azurechaos-disk-detach.yaml
字段说明
下表展示了 YAML 配置文件中的字段。
| Parameter | Type | Description | Default value | Required | Example |
|---|---|---|---|---|---|
| action | string | Indicates the specific type of faults. Only vm-stop, vm-restart, and disk-detach are supported. | vm-stop | Yes | vm-stop |
| 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). | N/A | 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. | N/A | No | 1 |
| secretName | string | Specifies the name of the Kubernetes Secret that stores the Azure authentication information. | N/A | No | cloud-key-secret |
| subscriptionID | string | Specifies the VM instacnce's subscription ID. | N/A | Yes | your-subscription-id |
| resourceGroupName | string | Specifies the Resource group of VM. | N/A | Yes | your-resource-group-name |
| vmName | string | VMName defines the name of Virtual Machine. | N/A | Yes | your-vm-name |
| diskName | string | This is a required field when the action is disk-detach, specifies the name of data disk. | N/A | No | DATADISK_0 |
| lun | string | This is a required field when the action is disk-detach, specifies the LUN (Logic Unit Number) of data disk. | N/A | No | 0 |
| duration | string | Specifies the duration of the experiment. | N/A | Yes | 30s |