跳至主内容
版本:下一版本

模拟 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_idclient_secret 的详细信息,请参考机密客户端应用程序

备注

请确保 Secret 文件中的应用注册已被添加为 VM 实例访问控制 (IAM) 的参与者或所有者。

使用 Chaos Dashboard 创建实验

  1. 打开 Chaos Dashboard,点击页面上的 新建实验 按钮:

    img
    img

  2. 选择目标 区域,选择 AZURE 故障 并指定具体行为(如 VM 停止)。

  3. 填写实验信息,指定实验范围和计划持续时间。

  4. 提交实验信息。

使用 YAML 文件创建实验

vm-stop 配置示例

  1. 将以下实验配置写入 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

  2. 配置文件准备完成后,使用 kubectl 创建实验:

    kubectl apply -f azurechaos-vm-stop.yaml

vm-restart 配置示例

  1. 将实验配置写入 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

  2. 配置文件准备就绪后,使用 kubectl 创建实验:

    kubectl apply -f azurechaos-vm-restart.yaml

detach-volume 配置示例

  1. 将实验配置写入 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 文档 - 分离数据磁盘

  2. 配置文件准备就绪后,使用 kubectl 创建实验:

    kubectl apply -f azurechaos-disk-detach.yaml

字段说明

下表展示了 YAML 配置文件中的字段。

ParameterTypeDescriptionDefault valueRequiredExample
actionstringIndicates the specific type of faults. Only vm-stop, vm-restart, and disk-detach are supported.vm-stopYesvm-stop
modestringSpecifies 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/AYesone
valuestringProvides parameters for the mode configuration, depending on mode. For example, when mode is set to fixed-percent, value specifies the percentage of Pods.N/ANo1
secretNamestringSpecifies the name of the Kubernetes Secret that stores the Azure authentication information.N/ANocloud-key-secret
subscriptionIDstringSpecifies the VM instacnce's subscription ID.N/AYesyour-subscription-id
resourceGroupNamestringSpecifies the Resource group of VM.N/AYesyour-resource-group-name
vmNamestringVMName defines the name of Virtual Machine.N/AYesyour-vm-name
diskNamestringThis is a required field when the action is disk-detach, specifies the name of data disk.N/ANoDATADISK_0
lunstringThis is a required field when the action is disk-detach, specifies the LUN (Logic Unit Number) of data disk.N/ANo0
durationstringSpecifies the duration of the experiment.N/AYes30s