Pod CPU hog
Pod CPU hog is a Kubernetes pod-level chaos fault that excessively consumes CPU resources, resulting in a significant increase in the CPU resource usage of a pod.
- Simulates a situation where an application's CPU resource usage unexpectedly spikes.
Usage
View fault usage
Prerequisites
- Kubernetes> 1.16.
Default validations
The application pods should be in running state before and after chaos injection.
Fault tunables
Fault tunables
Optional fields
Variables | Description | Notes |
---|---|---|
CPU_CORES | Number of the CPU cores subjected to CPU stress | Default to 1 |
TOTAL_CHAOS_DURATION | The time duration for chaos insertion (seconds) | Default to 60s |
LIB_IMAGE | Image used to run the helper pod. | Defaults to litmuschaos/go-runner:1.13.8 |
STRESS_IMAGE | Container run on the node at runtime by the pumba lib to inject stressors. Only used in LIB pumba | Default to alexeiled/stress-ng:latest-ubuntu |
TARGET_PODS | Comma separated list of application pod name subjected to pod CPU hog chaos | If not provided, it will select target pods randomly based on provided appLabels |
TARGET_CONTAINER | Name of the target container under chaos | If not provided, it will select the first container of the target pod |
PODS_AFFECTED_PERC | The Percentage of total pods to target | Defaults to 0 (corresponds to 1 replica), provide numeric value only |
CONTAINER_RUNTIME | container runtime interface for the cluster | Defaults to docker, supported values: docker, containerd and crio for litmus and only docker for pumba LIB |
SOCKET_PATH | Path of the containerd/crio/docker socket file | Defaults to /var/run/docker.sock |
RAMP_TIME | Period to wait before injection of chaos in sec | For example, 30 |
SEQUENCE | It defines sequence of chaos execution for multiple target pods | Default value: parallel. Supported: serial, parallel |
Fault examples
Common and pod-specific tunables
Refer to the common attributes and pod-specific tunables to tune the common tunables for all fault and pod specific tunables.
CPU Cores
It specifies the number of CPU cores to target for a duration specified by TOTAL_CHAOS_DURATION
environment variable. You can tune it using the CPU_CORE
environment variable.
Use the following example to tune tithis:
# CPU cores for the stress
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
annotationCheck: "false"
appinfo:
appns: "default"
applabel: "app=nginx"
appkind: "deployment"
chaosServiceAccount: litmus-admin
experiments:
- name: pod-cpu-hog
spec:
components:
env:
# CPU cores for stress
- name: CPU_CORES
value: '1'
- name: TOTAL_CHAOS_DURATION
value: '60'
CPU load
It contains percentage of pod CPU to be consumed. You can tune it using the CPU_LOAD
ENV.
Use the following example to tune it:
# CPU load for the stress
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
annotationCheck: "false"
appinfo:
appns: "default"
applabel: "app=nginx"
appkind: "deployment"
chaosServiceAccount: litmus-admin
experiments:
- name: pod-cpu-hog
spec:
components:
env:
# CPU load in percentage for the stress
- name: CPU_LOAD
value: "100"
# CPU core should be provided as 0 for CPU load
# to work, otherwise it will take CPU core as priority
- name: CPU_CORES
value: "0"
- name: TOTAL_CHAOS_DURATION
value: "60"
Container runtime and socket path
It defines the CONTAINER_RUNTIME
and SOCKET_PATH
ENV to set the container runtime and socket file path.
CONTAINER_RUNTIME
: It supportsdocker
,containerd
, andcrio
runtimes. The default value isdocker
.SOCKET_PATH
: It contains path of docker socket file by default(/var/run/docker.sock
). Forcontainerd
, specify path as/var/containerd/containerd.sock
. Forcrio
, speecify path as/var/run/crio/crio.sock
.
Use the following example to tune it:
## provide the container runtime and socket file path
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
annotationCheck: "false"
appinfo:
appns: "default"
applabel: "app=nginx"
appkind: "deployment"
chaosServiceAccount: litmus-admin
experiments:
- name: pod-cpu-hog
spec:
components:
env:
# runtime for the container
# supports docker, containerd, crio
- name: CONTAINER_RUNTIME
value: "docker"
# path of the socket file
- name: SOCKET_PATH
value: "/var/run/docker.sock"
- name: TOTAL_CHAOS_DURATION
VALUE: "60"