跳至主内容
版本:下一版本

模拟时间故障

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

TimeChaos 介绍

Chaos Mesh 提供了 TimeChaos 实验类型。您可以使用该实验类型模拟时间偏移场景。本文档介绍如何创建 TimeChaos 实验及其关联的配置文件。

备注

TimeChaos 仅影响容器 PID 命名空间中的 PID 1 进程和 PID 1 的子进程。例如,通过 kubectl exec 启动的进程不会受到影响。

您可以通过 Chaos Dashboard 或 YAML 配置文件创建实验。

使用 Chaos Dashboard 创建实验

  1. 打开 Chaos Dashboard,点击页面上的 新建实验 创建新实验:

    Create Experiment
    Create Experiment

  2. 选择目标 区域,选择 时钟偏移 并填写时钟 ID 和时间偏移量:

    TimeChaos 实验
    TimeChaos 实验

  3. 填写实验信息,并指定实验范围和计划的实验持续时间:

    实验信息
    实验信息

  4. 提交实验信息。

使用 YAML 文件创建实验

  1. 将实验配置写入 YAML 配置文件。以下示例使用 time-shift.yaml 文件:

    apiVersion: chaos-mesh.org/v1alpha1
    kind: TimeChaos
    metadata:
    name: time-shift-example
    namespace: chaos-mesh
    spec:
    mode: one
    selector:
    labelSelectors:
    'app': 'app1'
    timeOffset: '-10m100ns'

    此实验配置将使指定 Pod 中进程的时间向前偏移 10 分钟 100 纳秒。

  2. 配置文件准备完成后,使用 kubectl 创建实验:

    kubectl apply -f time-shift.yaml

YAML 配置文件中的字段如下表所述:

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