Create Chaos Mesh Workflow

    When you use Chaos Mesh to simulate real system faults, continuous validation is always a need. You might want to build a series of faults on the Chaos Mesh platform, instead of performing individual Chaos injections.

    To meet this need, Chaos Mesh provided Chaos Mesh Workflow, a built-in workflow engine. Using this engine, you can run different Chaos experiments in serial or parallel to simulate production-level errors.

    Currently, Chaos Mesh Workflow supports the following features:

    • Serial Orchestration
    • Parallel Orchestration
    • Customized tasks
    • Conditional branch

    Typical user scenarios:

    • Use parallel orchestration to inject multiple NetworkChaos faults to simulate complex web environments.
    • Use serial orchestration to perform health checks and use the conditional branch to determine whether to perform the remaining steps.

    The design of Chaos Mesh Workflow is, to some extent, inspired by Argo Workflows. If you are familiar with Argo Workflows, you can also quickly get started with Chaos Mesh Workflow.

    More workflow examples are available in the Chaos Mesh GitHub repository.

    Click NEW WORKFLOW.

    Step 2. Setup basic information of the workflow

    Workflow Info

    Step 3. Configure the nodes of the workflow

    1. Select an option under Choose task type according to your needs.

    :::

      1. Fill out the experiment information.

        The configuration method is the same as creating a normal chaos experiment. For example, you can set up a “POD KILL” type of “PodChaos” named kill-nginx.

      You can check workflow definition through Preview, and then click the SUBMIT WORKFLOW to create the workflow.

      Submit Workflow

      Similar to various types of Chaos objects, workflows also exist in a Kubernetes cluster as a CRD. You can create a Chaos Mesh workflow using kubectl create -f <workflow.yaml>. The following command is an example of creating a workflow. Create a workflow using a local YAML file:

      Create a workflow using a YAML file from the network:

      1. kubectl create -f https://raw.githubusercontent.com/chaos-mesh/chaos-mesh/master/examples/workflow/serial.yaml

      A simple workflow YAML file is defined as follows. In this workflow, StressChaos, NetworkChaos, and PodChaos are injected:

      Each element in templates represents a workflow step. For example:

      1. name: the-entry
      2. templateType: Parallel
      3. deadline: 240s
      4. children:
      5. - workflow-network-chaos
      6. - workflow-pod-chaos

      templateType: Parallel means that the node type is parallel. deadline: 240s means that all parallel experiments on this node are expected to be performed in 240 seconds; otherwise, the experiments time out. children means the other template names to be executed in parallel.

      For example:

      templateType: PodChaos means that the node type is PodChaos experiments. deadline: 40s means that the current Chaos experiment lasts for 40 seconds. podChaos is the definition of the PodChaos experiment.

      It is flexible to create a workflow using a YAML file and kubectl. You can nest parallel or serial orchestrations to declare complex orchestrations, and even combine the orchestration with conditional branches to achieve a circular effect.

      Workflow field description

      Template field description

      note

      When creating a Chaos with a duration in the workflow, you need to fill the duration in the outer deadline field instead of using the duration field in Chaos.

      Conditional branch field description

      Currently, two context variables are provided in expression:

      • exitCode means the exit code for a customized task.

      Refer to write expression expressions.

      Container field description