Run a Chaos Experiment

    You can create the following types of Chaos experiments in Chaos Mesh:

    • One-time Chaos experiments: The smallest instance of Chaos experiments. Once a one-time experiment is created, Chaos Mesh immediately injects faults into the target test machine according to the experiment configurations. If the parameter is configured, injected faults will be restored automatically after a period of time specified by duration. When the Chaos experiment is paused or deleted, injected faults will be restored immediately.
    • Scheduled or cyclic Chaos experiments: Chaos experiments that can be run at a regular interval or cyclically. You need to define the scheduling rules for the experiment when creating this type of Chaos experiment.

    To create a one-time Chaos experiment, you can use one of the following methods:

    • Use Chaos Dashboard to create a new Chaos experiment, then click Submit to run the experiment. For more details, refer to the documentation of each specific Chaos experiment type.
    • Use a YAML file to define the Chaos experiment, then create and run the experiment using kubectl. If you want to create and run a Chaos experiment in this way, take the following steps:
    1. Create a new YAML file to define a Chaos experiment. Add configuration parameters in the file based on the type of Chaos experiment you want to create.

      Take a NetworkChaos experiment as an example. Save the following YAML text as network-delay.yaml.

      The above YAML example defines a network latency fault lasting for 12 seconds, targeting applications with the "app": "web-show" tag under the default namespace. For more configuration information about the NetworkChaos experiment, refer to Simulate network chaos.

    2. Execute the following command to create and run this Chaos experiment.

      1. kubectl apply -f network-delay.yaml

    Scheduled or cyclic Chaos experiments

    Chaos Mesh offers the Schedule object to create scheduled Chaos experiments and cyclic Chaos experiments.

    1. Create a new YAML file to define a Chaos experiment. You need to configure the Schedule parameter in the YAML file to define specific schedule rules for the experiment, and then configure other parameters according to the type of Chaos experiments you want to create.

      Take a scheduled NetworkChaos experiment as an example. Save the following YAML text as schedule-delay-example.yaml.

      The above YAML example defines a network latency fault that can be automatically triggered at the fifth minute of each hour.For detailed introduction of scheduling rules, refer to Define scheduling rules.

      note

      If you do not set the duration parameter, the fault behavior keeps taking effect until you pause or delete the Chaos experiment.

    2. Execute the following command to create and run this Chaos experiment.

      1. kubectl apply -f schedule-delay-example.yaml
    3. To view the running status of the Chaos experiment after it begins, use the following kubectl describe command to check the or event of this experiment object.

      1. kubectl describe networkchaos schedule-delay-example

      For detailed steps to check the result of the Chaos experiment, refer to .

    For a running Chaos experiment, you can pause the experiment by setting a pause annotation to it using commands.

    After this command is executed, Chaos Mesh restores the injected faults immediately. If you want to resume this Chaos experiment from the pause state to the normal running state, use the following command:

    1. kubectl annotate networkchaos network-delay experiment.chaos-mesh.org/pause-

    Pause or resume Chaos experiments using Chaos Dashboard

    If you want to pause or resume a Chaos experiment using Chaos Dashboard, find the Chaos experiment you want on the Dashboard and click the Pause button or the Start button.

    Pause experiment

    The Spec field of Chaos experiment is currently not allowed to be updated.

    For more details, refer to the related .

    Update Chaos experiments using Chaos Dashboard

    The Chaos Dashboard doesn’t support updating Chaos experiments at this time because the Spec field of Chaos experiments is not allowed to be updated.

    After a Chaos experiment finishes, you can delete the experiment using the following kubectl delete command. Once you delete the Chaos experiment, the injected fault will be restored immediately:

    1. kubectl delete -f network-delay.yaml

    If the delete operation is blocked, this means that some fault behaviors of the target object cannot be restored. You can check the Chaos Mesh logs for troubleshooting or directly create a to report this problem to the Chaos Mesh team. Besides, you can forcibly delete the Chaos experiment with the following command:

    Delete Chaos experiments using Chaos Dashboard

    Archive experiment