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

Usage

View fault usage
This 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.
  • Kubernetes secret that has the GCP service account credentials in the default namespace. Below is a sample secret file:
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:

Default validations

The VM instances should be in a healthy state.

Fault tunables

Fault tunables

Mandatory Fields

Variables Description Notes
GCP_PROJECT_ID The ID of the GCP project, to which the VM instances belong. All the VM instances must belong to a single GCP project.
VM_INSTANCE_NAMES Name of the target VM instances. Multiple instance names can be provided as instance1,instance2,... and so on.
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.

Optional Fields

Variables Description Notes
TOTAL_CHAOS_DURATION Duration that you specify, through which chaos is injected into the target resource (in seconds). Defaults to 30s.
CHAOS_INTERVAL Time interval between two successive instance terminations (in seconds). Defaults to 30s.
MANAGED_INSTANCE_GROUP It is set to enable if the target instance is a part of the managed instance group. Defaults to disable.
SEQUENCE Sequence of chaos execution for multiple target instances. Defaults to parallel. It supports serial sequence as well.
RAMP_TIME Period to wait before and after injecting chaos (in seconds). For example, 30s.

Fault examples

Common fault tunables

Refer to the common attributes to tune the common tunables for all the faults.

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.

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.

Use the following example to tune it:

## 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

If the VM instances belong to a managed instance group, set the MANAGED_INSTANCE_GROUP environment variable to enable, otherwise set it disable (the default value).

Use the following example to tune it:

## 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'

Mutiple iterations of chaos

It defines the delay between every chaos iteration. You can tune different iterations of this iterating using the CHAOS_INTERVAL environment variable.

Use the following example to tune it:

# 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'