GCP VM instance stop by label
GCP VM instance stop by label powers off from the GCP VM instances (filtered by a label before) for a specific duration.
Use cases
GCP VM instance stop by label fault determines the resilience of an application that runs on a VM instance when a VM instance unexpectedly stops (or fails).
Prerequisites
- Kubernetes > 1.16
- Adequate GCP permissions to stop and start the GCP VM instances.
- The VM instances with the target label should be in a healthy state.
- Kubernetes secret should have the GCP service account credentials in the default namespace. Refer generate the necessary credentials in order to authenticate your identity with the Google Cloud Platform (GCP) docs for more information.
apiVersion: v1
kind: Secret
metadata:
name: cloud-secret
type: Opaque
stringData:
type:
project_id:
private_key_id:
private_key:
client_email:
client_id:
auth_uri:
token_uri:
auth_provider_x509_cert_url:
client_x509_cert_url:
Mandatory tunables
Tunable | Description | Notes |
---|---|---|
GCP_PROJECT_ID | Id of the GCP project that belong to the VM instances. | All the VM instances should belong to a single GCP project. For more information, go to GCP project ID. |
INSTANCE_LABEL | Name of the target VM instances. | This value is provided as key:value pair or as a key if the corresponding value is empty. For example, vm:target-vm . For more information, go to target GCP instances. |
ZONES | The zone of the target VM instances. | Only one zone is provided, that is, all the target instances should reside in the same zone. For more information, go to zones. |
Optional tunables
Tunable | Description | Notes |
---|---|---|
TOTAL_CHAOS_DURATION | Duration that you specify, through which chaos is injected into the target resource (in seconds). | Defaults to 30s. For more information, go to duration of the chaos. |
CHAOS_INTERVAL | Time interval between two successive instance terminations (in seconds). | Defaults to 30s. For more information, go to chaos interval. |
MANAGED_INSTANCE_GROUP | It is set to enable if the target instance is a part of the managed instance group. The fault doesn't start the VM instances after the duration when this variable is set. Instead, the fault checks the instance group for new instances. | Defaults to disable . For more information, go to managed instance group. |
INSTANCE_AFFECTED_PERC | Percentage of the total VMs filtered using the target label (specify numeric values only). | Defaults to 0 (corresponds to 1 instance). For more information, go to instance affected percentage. |
SEQUENCE | Sequence of chaos execution for multiple target instances. | Defaults to parallel. It supports serial sequence as well. For more information, go to sequence of chaos execution. |
RAMP_TIME | Period to wait before and after injecting chaos (in seconds). | For example, 30s. For more information, go to ramp time. |
DEFAULT_HEALTH_CHECK | Determines if you wish to run the default health check which is present inside the fault. | Default: 'true'. For more information, go to default health check. |
IAM permissions
Listed below are the IAM permissions leveraged by the fault:
compute.instances.list
compute.instances.get
compute.instances.stop
compute.instances.start
Target GCP instances
It stops all the instances that are filtered using the INSTANCE_LABEL
label in the ZONES
zone in the GCP_PROJECT_ID
project.
GCP project ID: The project ID which is a unique identifier for a GCP project. Tune it by using the GCP_PROJECT_ID
environment variable.
Zones: The zone of the disk volumes subject to the fault. Tune it by using the ZONES
environment variable.
Note: INSTANCE_LABEL
environment variable accepts only one label and ZONES
accepts only one zone name. Therefore, all the instances must reside in the same zone.
The following YAML snippet illustrates the use of this environment variable:
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
chaosServiceAccount: litmus-admin
experiments:
- name: gcp-vm-instance-stop-by-label
spec:
components:
env:
- name: INSTANCE_LABEL
value: 'vm:target-vm'
- name: ZONES
value: 'us-east1-b'
- name: GCP_PROJECT_ID
value: 'my-project-4513'
- name: TOTAL_CHAOS_DURATION
VALUE: '60'
Managed instance group
Check if the VM instances belong to a managed instance group. If so, set the MANAGED_INSTANCE_GROUP
environment variable to enable
, else disable
. Its default value is disable
.
Instance affected percentage: The number of VMs filtered using the target label. It defaults to 0 that corresponds to a single instance. Tune it by using the INSTANCE_AFFECTED_PERC
environment variable.
The following YAML snippet illustrates the use of this environment variable:
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
chaosServiceAccount: litmus-admin
experiments:
- name: gcp-vm-instance-stop-by-label
spec:
components:
env:
- name: MANAGED_INSTANCE_GROUP
value: 'enable'
- name: INSTANCE_LABEL
value: 'vm:target-vm'
- name: ZONES
value: 'us-east1-b'
- name: GCP_PROJECT_ID
value: 'my-project-4513'
- name: TOTAL_CHAOS_DURATION
VALUE: '60'
- name: INSTANCE_AFFECTED_PERC
VALUE: "0"