Skip to main content

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.

  • When the MANAGED_INSTANCE_GROUP environment variable is set to enable, the fault does not start the VM instances after chaos. Instead, the fault checks the instance group for new instances.

GCP VM Instance Stop By Label

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

All the VM instances that contain the target label are 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 should belong to a single GCP project.
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.
ZONES The zone of the target VM instances. Only one zone is provided, i.e. all the target instances should reside in the same zone.

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.
INSTANCE_AFFECTED_PERC Percentage of the total VMs filtered using the target label (specify numeric values only). Defaults to 0 (corresponds to 1 instance).
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 that are filtered using the INSTANCE_LABEL label in the ZONES zone in the GCP_PROJECT_ID project.

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.

Use the following example to tune it:

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'

Manged 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:

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'