当前位置: 首页 > 工具软件 > Chaos Mesh > 使用案例 >

【Chaos Mesh官方文档】(Kubernetes)Simulate Time Faults

郤玉书
2023-12-01

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.
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.

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

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

Create Experiment

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

TimeChaos Experiments

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

Experiment Information

Submit the experiment information.

Create experiments using the YAML file​

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

apiVersion: chaos-mesh.org/v1alpha1
kind: TimeChaos
metadata:
  name: time-shift-example
  namespace: chaos-testing
spec:
  mode: one
  selector:
    labelSelectors:
      '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.

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:
Parameter Type Note Default value Required Example
timeOffset string Specifies the length of time offset. None Yes -5m
clockIds []string Specifies the ID of clock that will be offset. See the clock_gettime documentation for details. [“CLOCK_REALTIME”] No [“CLOCK_REALTIME”, “CLOCK_MONOTONIC”]
mode string Specifies 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). None Yes one
value string Provides parameters for the mode configuration, depending on mode.For example, when mode is set to fixed-percent, value specifies the percentage of Pods. None No 1
containerNames []string Specifies the name of the container into which the fault is injected. None No [“nginx”]
selector struct Specifies the target Pod. For details, refer to Define the experiment scope. None Yes

 类似资料: