Skip to main content
Version: release-0.8

Simulate stress faults

StressChaos experiments simulate stress scenarios inside containers. This document describes how to create StressChaos experiments.

OptionDescriptionDefault valueRequired
--cpu-workerIt specifies the number of threads that exert CPU stress. One of --cpu-worker and --memory-worker must be specified.NoneNo
--cpu-loadIt specifies the percentage of occupied CPU. 0 means no extra load added and 100 means full load. The total load is workers * load.20No
--memory-workerIt specifies the number of threads that exert memory pressure. One of --cpu-worker and --memory-worker must be specified.NoneNo
--memory-sizeIt specifies the size of the allocated memory or the percentage of the total memory occupied, and the sum of the allocated memory is size.NoneNo
--containerIt specifies a container name and multiple containers can be specified. If not specified, it defaults to the first container in the Pod.NoneNo

Simulate fault injections by kbcli

The command below creates a process in the first container of all pods in the default namespace and continuously allocates and reads and writes in CPU and memory, occupying up to 100 MB of memory for 10 seconds. During this process, 2 threads exert CPU stress and 1 thread that exerts memory stress.

kbcli fault stress --cpu-worker=2 --cpu-load=50 --memory-worker=1 --memory-size=100Mi

Simulate fault injections by YAML file

This section introduces the YAML configuration file examples. You can view the YAML file by adding --dry-run at the end of the above kbcli commands. Meanwhile, you can also refer to the Chaos Mesh official docs for details.

Stress example

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

    In the following example, Chaos Mesh creates a process in the first container of all pods in the default namespace and continuously allocates and reads and writes in CPU and memory, occupying up to 100MB of memory for 10 seconds. During this process, 2 threads exert CPU stress and 1 thread that exerts memory stress.

    apiVersion: chaos-mesh.org/v1alpha1
    kind: StressChaos
    metadata:
    creationTimestamp: null
    generateName: stress-chaos-
    namespace: default
    spec:
    duration: 10s
    mode: all
    selector:
    namespaces:
    - default
    stressors:
    cpu:
    load: 50
    workers: 2
    memory:
    size: 100Mi
    workers: 1
  2. Run kubectl to start an experiment.

    kubectl apply -f ./stress.yaml