Skip to main content

GCP VM instance stop

GCP VM instance stop powers off from a GCP VM instance using the instance name (or a list of instance names) before for a specific duration.

  • This fault checks the performance of the application (or process) running on the VM instance.
  • When the MANAGED_INSTANCE_GROUP environment variable is set to enable, the fault does not start the instances after chaos. Instead, the fault checks the instance group for new instances.

GCP VM Instance Stop

Use cases

GCP VM instance stop fault determines the resilience of an application that runs on a VM instance when a VM instance unexpectedly stops (or fails).

Prerequisites

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 must belong to a single GCP project. For more information, go to GCP project ID.
VM_INSTANCE_NAMES Name of the target VM instances. Multiple instance names can be provided as instance1,instance2,... and so on. For more information, go to target GCP instances.
ZONES The zones of the target VM instances. Zone for every instance name is provided as zone1,zone2,... and so on, in the same order as VM_INSTANCE_NAMES. 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. Defaults to disable. For more information, go to managed instance group.
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_CHECKDetermines 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.get
  • compute.instances.stop
  • compute.instances.start

Target GCP instances

It stops all the instances with the VM_INSTANCE_NAMES instance names 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: VM_INSTANCE_NAMES environment variable contains multiple comma-separated VM instances. The comma-separated zone names should be provided in the same order as the instance names.

The following YAML snippet illustrates the use of this environment variable:

## details of the GCP instance
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
chaosServiceAccount: litmus-admin
experiments:
- name: gcp-vm-instance-stop
spec:
components:
env:
# comma-separated list of vm instance names
- name: VM_INSTANCE_NAMES
value: 'instance-01,instance-02'
# comma-separated list of zone names corresponds to the VM_INSTANCE_NAMES
# it should be provided in same order of VM_INSTANCE_NAMES
- name: ZONES
value: 'zone-01,zone-02'
# GCP project ID to which vm instance belongs
- name: GCP_PROJECT_ID
value: 'project-id'

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.

The following YAML snippet illustrates the use of this environment variable:

## scale up and down to maintain the available instance counts
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
chaosServiceAccount: litmus-admin
experiments:
- name: gcp-vm-instance-stop
spec:
components:
env:
# tells if instances are part of managed instance group
# supports: enable, disable. default: disable
- name: MANAGED_INSTANCE_GROUP
value: 'enable'
# comma-separated list of vm instance names
- name: VM_INSTANCE_NAMES
value: 'instance-01,instance-02'
# comma-separated list of zone names corresponds to the VM_INSTANCE_NAMES
# it should be provided in same order of VM_INSTANCE_NAMES
- name: ZONES
value: 'zone-01,zone-02'
# GCP project ID to which vm instance belongs
- name: GCP_PROJECT_ID
value: 'project-id'
- name: TOTAL_CHAOS_DURATION
VALUE: '60'

Multiple iterations of chaos

The delay between every chaos iteration. Tune the different iterations using the CHAOS_INTERVAL environment variable.

The following YAML snippet illustrates the use of this environment variable:

# defines delay between each successive iteration of the chaos
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
annotationCheck: "false"
chaosServiceAccount: gcp-vm-instance-stop-sa
experiments:
- name: gcp-vm-instance-stop
spec:
components:
env:
# delay between each iteration of chaos
- name: CHAOS_INTERVAL
value: '15'
# duration for the chaos execution
- name: TOTAL_CHAOS_DURATION
VALUE: '60'
- name: VM_INSTANCE_NAMES
value: 'instance-01,instance-02'
- name: ZONES
value: 'zone-01,zone-02'
- name: GCP_PROJECT_ID
value: 'project-id'