github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docs/developer_docs/fault_injection/aws-fault.md (about) 1 --- 2 title: Simulate AWS faults 3 description: Simulate AWS faults 4 sidebar_position: 10 5 sidebar_label: Simulate AWS faults 6 --- 7 8 # Simulate AWS faults 9 10 AWSChaos simulates fault scenarios on the specified AWS instance. Currently, AWSChaos supports the following fault types: 11 12 * EC2 Stop: stops the specified instance. 13 * EC2 Restart: restarts the specified instance. 14 * Detach Volume: uninstalls the storage volume from the specified instance. 15 16 ## Before you start 17 18 * By default, the AWS authentication information for local code has been imported. If you have not imported the authentication, follow the steps in [Prerequisite](./prerequisite.md#check-your-permission). 19 20 * To connect to the AWS cluster easily, you can create a Kubernetes Secret file in advance to store authentication information. A `Secret` file sample is as follows: 21 22 ```yaml 23 apiVersion: v1 24 kind: Secret 25 metadata: 26 name: cloud-key-secret-aws 27 namespace: default 28 type: Opaque 29 stringData: 30 aws_access_key_id: your-aws-access-key-id 31 aws_secret_access_key: your-aws-secret-access-key 32 ``` 33 34 * `name` means the Kubernetes Secret object. 35 * `namespace` means the namespace of the Kubernetes Secret object. 36 * `aws_access_key_id` stores the ID of the access key to the AWS cluster. 37 * `aws_secret_access_key` stores the secret access key to the AWS cluster. 38 39 ## Simulate fault injections by kbcli 40 41 ### Stop 42 43 Chaos Mesh injects an `instance-stop` fault into the specified EC2 instance so that this instance will be unavailable in 3 minutes. 44 45 ```bash 46 kbcli fault node stop [node1] -c=aws --region=cn-northwest-1 --duration=3m 47 ``` 48 49 ### Restart 50 51 Chaos Mesh inject an `instance-restart` fault into the specified EC2 instance so that this instance will be restarted. 52 53 ```bash 54 kbcli fault node restart [node1] -c=aws --region=cn-northwest-1 --duration=3m 55 ``` 56 57 ### Detach volume 58 59 Chaos Mesh injects a `detach-volume` fault into the specified EC2 instance so that this instance is detached from the specified storage volume within 3 minutes. 60 61 ```bash 62 kbcli fault node detach-volume [node1] -c=aws --region=cn-northwest-1 --duration=1m --volume-id=vol-xxx --device-name=/dev/xvdaa 63 ``` 64 65 You can also add multiple nodes and their volumes. For example, 66 67 ```bash 68 kbcli fault node detach-volume [node1] [node2] -c=aws --region=cn-northwest-1 --duration=1m --volume-id=vol-xxx,vol-xxx --device-name=/dev/sda,/dev/sdb 69 ``` 70 71 ## Simulate fault injections by YAML file 72 73 This section introduces the YAML configuration file examples. You can also refer to the [Chaos Mesh official docs](https://chaos-mesh.org/docs/next/simulate-time-chaos-on-kubernetes/#create-experiments-using-the-yaml-file) for details. 74 75 ### AWS-stop example 76 77 1. Write the experiment configuration to the `aws-stop.yaml` file. 78 79 In the following example, Chaos Mesh injects an `instance-stop` fault into the specified EC2 instance so that this instance will be unavailable in 3 minutes. 80 81 ```yaml 82 apiVersion: chaos-mesh.org/v1alpha1 83 kind: AWSChaos 84 metadata: 85 creationTimestamp: null 86 generateName: node-chaos- 87 namespace: default 88 spec: 89 action: ec2-stop 90 awsRegion: cn-northwest-1 91 duration: 3m 92 ec2Instance: i-037b1f38debb59bd7 93 secretName: cloud-key-secret-aws 94 ``` 95 96 2. Run `kubectl` to start an experiment. 97 98 ```bash 99 kubectl apply -f ./aws-stop.yaml 100 ``` 101 102 ### AWS-restart example 103 104 1. Write the experiment configuration to the `aws-restart.yaml` file. 105 106 In the following example, Chaos Mesh inject an `instance-restart` fault into the specified EC2 instance so that this instance will be restarted. 107 108 ```yaml 109 apiVersion: chaos-mesh.org/v1alpha1 110 kind: AWSChaos 111 metadata: 112 creationTimestamp: null 113 generateName: node-chaos- 114 namespace: default 115 spec: 116 action: ec2-restart 117 awsRegion: cn-northwest-1 118 duration: 3m 119 ec2Instance: i-037b1f38debb59bd7 120 secretName: cloud-key-secret-aws 121 ``` 122 123 2. Run `kubectl` to start an experiment. 124 125 ```bash 126 kubectl apply -f ./aws-restart.yaml 127 ``` 128 129 ### AWS-detach-volume example 130 131 1. Write the experiment configuration to the `aws-detach-volume.yaml` file. 132 133 In the following example, Chaos Mesh injects a `detach-volume` fault into the two specified EC2 instance so that these two instance is detached from their own storage volume within 3 minutes. 134 135 ```yaml 136 apiVersion: chaos-mesh.org/v1alpha1 137 kind: AWSChaos 138 metadata: 139 creationTimestamp: null 140 generateName: node-chaos- 141 namespace: default 142 spec: 143 action: detach-volume 144 awsRegion: cn-northwest-1 145 deviceName: /dev/xvda 146 duration: 1m 147 ec2Instance: i-0e368667e544fa955 148 secretName: cloud-key-secret-aws 149 volumeID: vol-01b3d68c074cd93a9 150 status: 151 experiment: {} 152 apiVersion: chaos-mesh.org/v1alpha1 153 kind: AWSChaos 154 metadata: 155 creationTimestamp: null 156 generateName: node-chaos- 157 namespace: default 158 spec: 159 action: detach-volume 160 awsRegion: cn-northwest-1 161 deviceName: /dev/xvdaa 162 duration: 1m 163 ec2Instance: i-01da8eef32743b5de 164 secretName: cloud-key-secret-aws 165 volumeID: vol-0f1ecf66cb8d0328e 166 ``` 167 168 2. Run `kubectl` to start an experiment. 169 170 ```bash 171 kubectl apply -f ./aws-detach-volume.yaml 172 ``` 173 174 ### Field description 175 176 The fields in the YAML configuration file are described in the following table: 177 178 | Parameter | Type | Description | Default value | Required | 179 | :--- | :--- | :--- | :--- | :--- | 180 | action | string | It indicates the specific type of faults. Only `ec2-stop`, `ec2-restore`, and `detain-volume` are supported. | ec2-stop | Yes | `ec2-stop` | 181 | mode | string | It 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 | 182 | value | string | It 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 | 183 | secretName | string | It specifies the name of the Kubernetes Secret that stores the AWS authentication information. | None | No | 184 | awsRegion | string | It specifies the AWS region. | None | Yes | us-east-2 | 185 | ec2Instance | string | It specifies the ID of the EC2 instance. | None | Yes | 186 | volumeID | string | This is a required field when the `action` is `detach-volume`. This field specifies the EBS volume ID. | None | No | 187 | deviceName | string | This is a required field when the `action` is `detach-volume`. This field specifies the machine name. | None | No | /dev/sdf | 188 | duration | string | It specifies the duration of the experiment. | None | Yes |