Skip to main content
Version: 2.4.3

Simulate Time Faults

TimeChaos Introduction

Chaos Mesh provides the TimeChaos experiment type. You can use this experiment type to simulate a time offset scenario. This document describes how to create a TimeChaos experiment and its associated configuration file.


TimeChaos only affects the PID 1 process in the PID namespace of the container, and child processes of the PID 1. For example, the process started by kubectl exec does not be affected.

You can create experiments in Chaos Dashboard or using the YAML configuration file.

Create experiments using Chaos Dashboard

  1. Open Chaos Dashboard, and click NEW EXPERIMENT on the page to create a new experiment:

    Create Experiment

  2. In the Choose a Target area, choose CLOCK SCREW and fill out the Clock ID and time offset.

    TimeChaos Experiments

  3. Fill out the experiment information, and specify the experiment scope and the scheduled experiment duration:

    Experiment Information

  4. Submit the experiment information.

Create experiments using the YAML file

  1. Write the experiment configuration to the YAML configuration file. In the following example, the time-shift.yaml file is used.

    kind: TimeChaos
    name: time-shift-example
    namespace: chaos-mesh
    mode: one
    'app': 'app1'
    timeOffset: '-10m100ns'

    This experiment configuration will shift the time of the processes in the specified Pod forward by 10 minutes and 100 nanoseconds.

  2. After the configuration file is prepared, use kubectl to create an experiment:

    kubectl apply -f time-shift.yaml

The fields in the YAML configuration file are described in the following table:

ParameterTypeNoteDefault valueRequiredExample
timeOffsetstringSpecifies the length of time offset.NoneYes-5m
clockIds[]stringSpecifies the ID of clock that will be offset. See the clock_gettime documentation for details.["CLOCK_REALTIME"]No["CLOCK_REALTIME", "CLOCK_MONOTONIC"]
modestringSpecifies the mode of the experiment. The mode options include one (selecting a random Pod), all (selecting all eligible Pods), fixed (selecting a specified number of eligible Pods), fixed-percent (selecting a specified percentage of Pods from the eligible Pods), and random-max-percent (selecting the maximum percentage of Pods from the eligible Pods).NoneYesone
valuestringProvides parameters for the mode configuration, depending on mode.For example, when mode is set to fixed-percent, value specifies the percentage of Pods.NoneNo1
containerNames[]stringSpecifies the name of the container into which the fault is injected.NoneNo["nginx"]
selectorstructSpecifies the target Pod. For details, refer to Define the experiment scope.NoneYes