Skip to main content
Version: release-0.8

Simulate time faults

You can use this experiment type to simulate a time offset scenario. This document describes how to create a TimeChaos experiment.

note

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.

OptionShortDescriptionDefault valueRequired
--time-offsetNoneIt specifies the length of time offset.NoneYes
--clock-idNoneIt specifies the ID of clock that will be offset. See the clock_gettime documentation for details.CLOCK_REALTIMENo
--container-cIt specifies a container name for fault injection.NoneNo

Simulate fault injections by kbcli

This experiment configuration shifts the time of the processes in the specified Pod forward by 5 seconds. Once this time fault is injected into the Pod, a failure occurs to this Pod and this Pod restarts.

kbcli fault time --time-offset=-5s

Simulate fault injections by YAML file

This section introduces the YAML configuration file examples. You can also refer to the Chaos Mesh official docs for details.

  1. Write the experiment configuration to the time.yaml file.

    In the following example, Chaos Mesh injects a time fault to shift the time of the processes in the specified Pod forward by 5 seconds. Once this time fault is injected into the Pod, a failure occurs to this Pod and this Pod restarts.

    apiVersion: chaos-mesh.org/v1alpha1
    kind: TimeChaos
    metadata:
    creationTimestamp: null
    generateName: time-chaos-
    namespace: default
    spec:
    duration: 10s
    mode: all
    selector:
    namespaces:
    - default
    timeOffset: -5s
  2. Run kubectl to start an experiment.

    kubectl apply -f ./time.yaml

Field description

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

ParameterTypeNoteDefault valueRequired
timeOffsetstringIt specifies the length of time offset.NoneYes
clockIds[]stringIt specifies the ID of clock that will be offset. See the clock_gettime documentation for details.["CLOCK_REALTIME"]No
modestringIt specifies the mode of an 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).NoneYes
valuestringIt provides parameters for the mode configuration, depending on mode. For example, when mode is set to fixed-percent, value specifies the percentage of Pods.NoneNo
containerNames[]stringIt specifies the name of the container into which the fault is injected.NoneNo
selectorstructIt specifies the target Pod.NoneYes