Define the Scope of Chaos Experiments

In Chaos Mesh, you can define the scope of a single Chaos experiment by specifying a selector.

Different types of selectors correspond to different filtering rules. You can specify one or more selectors in a Chaos experiment to define the scope of your experiment. If multiple selectors are specified at the same time, the current experiment target must meet the rules of all specified selectors at the same time.

When you create a Chaos experiment, Chaos Mesh supports the following ways to define the scope of an experiment. You can choose any one of the following ways as needed:

  • Define the experiment scope in a YAML configuration file
  • Define the experiment scope on the Chaos Dashboard

This section introduces the meanings of different selector types and their the usages, and provides the configuration examples in the YAML file. When defining the experiment scope in the YAML file, you can specify one or more selectors according to your need of scope filtering.

  • Specifies the namespace of the experiment’s target Pod.
  • Data type: string array type.
  • If this selector is empty or is not specified, Chaos Mesh will set it to the namespace of the current Chaos experiment.

When creating the experiment using the YAML file, you need to configure selectors. For example:

Label selectors

  • Specifies the that the experiment’s target Pod must have.
  • Data type: key-value pairs.
  • If multiple labels are specified, the experiment target must have all the labels specified by this selector.
  1. selector:
  2. labelSelectors:

Expression selectors

  • Specifies a set of that define the label’s rules to specifiy the experiment’s target Pod.
  • You can use this selector to set up the experiment’s target Pod that does not meet some labels.

When creating the experiment using the YAML file, you need to configure selectors. For example:

  1. spec:
  2. selector:
  3. expressionSelectors:
  4. - { key: tier, operator: In, values: [cache] }
  5. - { key: environment, operator: NotIn, values: [dev] }
  • Specifies the annotations that the experiment’s target Pod must have.
  • Data type: key-value pairs.
  • If multiple annotations are specified, the experiment target must have all annotations specified by this selector.

When creating the experiment using the YAML file, you need to configure selectors. For example:

Field selectors

  • Specifies the fields of the experiment’s target Pod.
  • Data type: key-value pairs.
  • If multiple fields are specified, the experiment target must have all fields set by this selector.

When creating the experiment using the YAML file, you need to configure selectors. For example:

  1. spec:
  2. selector:
  3. fieldSelectors:
  4. 'metadata.name': 'my-pod'

PodPhase selectors

  • Specifies the phase of the experiment’s target Pod.
  • Data type: string array type.
  • Supported phases: Pending, , Succeeded, Failed, Unknown.
  • This option is empty by default, which means that the target Pod’s phase is not limited.

When creating the experiment using the YAML file, you need to configure selectors. For example:

  1. spec:
  2. selector:
  3. podPhaseSelectors:
  4. - 'Running'
  • Specifies the node label to which the experiment’s target Pod belongs.
  • If multiple node labels are specified, the node to which the experiment’s target Pod belongs must have all labels specified by this selector.

When creating the experiment using the YAML file, you need to configure selectors. For example:

Node list selector

  • Specifies the node to which the experiment’s target Pod belongs.
  • Data type: string array type.
  • The target Pod can only belong to one node in the configured node list.
  1. spec:
  2. selector:
  3. nodes:
  4. - node1
  5. - node2

Pod list selector

  • Specifies the namespaces and list of the experiment’s target Pods.
  • Type of data: key-value pairs. The “keys” are the namespaces of the target and the “values” are the target Pod list.
  • If you have specified this selector, Chaos Mesh ignores other configured selectors.

When creating the experiment using the YAML file, you need to configure selectors. For example:

  1. spec:
  2. selector:
  3. pods:
  4. tidb-cluster: # namespace of the target pods
  5. - basic-tidb-0
  6. - basic-pd-0
  7. - basic-tikv-0
  8. - basic-tikv-1
  • Specifies the namespaces and list of the experiment’s target PhysicalMachines.
  • Type of data: key-value pairs. The “keys” are the namespaces of the target PhysicalMachine, and the “values” are the target PhysicalMachine list.
  • If you have specified this selector, Chaos Mesh ignores other configured selectors.
note

PhysicalMachine is a CRD (CustomResourcesDefinition) that represents a physical machine. To create , Chaos Mesh uses Chaosctl.

When creating the experiment using the YAML file, you need to configure selectors. For example:

If you use Chaos Dashboard to create a Chaos experiment, you can configure the Chaos experiment scope when filling out the experiment information.

The following selectors are currently available on Chaos Dashboard. You can specify one or more selectors according to the filtering requirements of the experiment scope:

  • Namespace selectors
  • Label selectors
  • Annotation selectors