This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

CPU Hog Scenario

Overview

The CPU Hog scenario is designed to create CPU pressure on one or more nodes in your Kubernetes/OpenShift cluster for a specified duration. This scenario helps you test how your cluster and applications respond to high CPU utilization.

How It Works

The scenario deploys a stress workload pod on targeted nodes. These pods use stress-ng to consume CPU resources according to your configuration. The workload runs for a specified duration and then terminates, allowing you to observe your cluster’s behavior under CPU stress.

When to Use

Use the CPU Hog scenario to:

  • Test your cluster’s ability to handle CPU resource contention
  • Validate that CPU resource limits and quotas are properly configured
  • Evaluate the impact of CPU pressure on application performance
  • Test whether your monitoring and alerting systems properly detect CPU saturation
  • Verify that the Kubernetes scheduler correctly handles CPU-constrained nodes
  • Simulate scenarios where rogue pods consume excessive CPU without limits

Key Configuration Options

In addition to the common hog scenario options, CPU Hog scenarios support:

Option Type Description
cpu-load-percentage number The percentage of CPU that will be consumed by the hog
cpu-method string The CPU load strategy adopted by stress-ng (see stress-ng documentation for available options)

How to Run CPU Hog Scenarios

Choose your preferred method to run CPU hog scenarios:

To enable this plugin add the pointer to the scenario input file scenarios/kube/cpu-hog.yml as described in the Usage section.

Example scenario file: cpu-hog.yml

cpu-hog options

In addition to the common hog scenario options, you can specify the below options in your scenario configuration to specificy the amount of CPU to hog on a certain worker node

Option Type Description
cpu-load-percentage number the amount of cpu that will be consumed by the hog
cpu-method string reflects the cpu load strategy adopted by stress-ng, please refer to the stress-ng documentation for all the available options

Usage

To enable hog scenarios edit the kraken config file, go to the section kraken -> chaos_scenarios of the yaml structure and add a new element to the list named hog_scenarios then add the desired scenario pointing to the hog.yaml file.

kraken:
    ...
    chaos_scenarios:
        - hog_scenarios:
            - scenarios/kube/cpu-hog.yml

Run

python run_kraken.py --config config/config.yaml

This scenario hogs the cpu on the specified node on a Kubernetes/OpenShift cluster for a specified duration. For more information refer the following documentation.

Run

If enabling Cerberus to monitor the cluster and pass/fail the scenario post chaos, refer docs. Make sure to start it before injecting the chaos and set CERBERUS_ENABLED environment variable for the chaos injection container to autoconnect.

$ podman run \
  --name=<container_name> \
  --net=host \
  --pull=always \
  --env-host=true \
  -v <path-to-kube-config>:/home/krkn/.kube/config:Z \
  -d containers.krkn-chaos.dev/krkn-chaos/krkn-hub:node-cpu-hog
$ podman logs -f <container_name or container_id> # Streams Kraken logs
$ podman inspect <container-name or container-id> \
  --format "{{.State.ExitCode}}" # Outputs exit code which can considered as pass/fail for the scenario
$ docker run $(./get_docker_params.sh) \
  --name=<container_name> \
  --net=host \
  --pull=always \
  -v <path-to-kube-config>:/home/krkn/.kube/config:Z \
  -d containers.krkn-chaos.dev/krkn-chaos/krkn-hub:node-cpu-hog
$ docker run \
  -e <VARIABLE>=<value> \
  --net=host \
  --pull=always \
  -v <path-to-kube-config>:/home/krkn/.kube/config:Z \
  -d containers.krkn-chaos.dev/krkn-chaos/krkn-hub:node-cpu-hog

$ docker logs -f <container_name or container_id> # Streams Kraken logs
$ docker inspect <container-name or container-id> \
  --format "{{.State.ExitCode}}" # Outputs exit code which can considered as pass/fail for the scenario

Supported parameters

The following environment variables can be set on the host running the container to tweak the scenario/faults being injected:

Example if –env-host is used:

export <parameter_name>=<value>

OR on the command line like example:

-e <VARIABLE>=<value>

See list of variables that apply to all scenarios here that can be used/set in addition to these scenario specific variables

Parameter Description Default
TOTAL_CHAOS_DURATION Set chaos duration (in sec) as desired 60
NODE_CPU_CORE Number of cores (workers) of node CPU to be consumed 2
NODE_CPU_PERCENTAGE Percentage of total cpu to be consumed 50
NAMESPACE Namespace where the scenario container will be deployed default
NODE_SELECTOR Defines the node selector for choosing target nodes. If not specified, one schedulable node in the cluster will be chosen at random. If multiple nodes match the selector, all of them will be subjected to stress. If number-of-nodes is specified, that many nodes will be randomly selected from those identified by the selector. ""
TAINTS List of taints for which tolerations need to be created. Example: [“node-role.kubernetes.io/master:NoSchedule”] []
NUMBER_OF_NODES Restricts the number of selected nodes by the selector ""
IMAGE The container image of the stress workload quay.io/krkn-chaos/krkn-hog

For example:

$ podman run \
  --name=<container_name> \
  --net=host \
  --pull=always \
  --env-host=true \
  -v <path-to-custom-metrics-profile>:/home/krkn/kraken/config/metrics-aggregated.yaml \
  -v <path-to-custom-alerts-profile>:/home/krkn/kraken/config/alerts \
  -v <path-to-kube-config>:/home/krkn/.kube/config:Z \
  -d containers.krkn-chaos.dev/krkn-chaos/krkn-hub:node-cpu-hog
krknctl run node-cpu-hog [--<parameter> <value>]

Can also set any global variable listed here

Parameter Description Type Required Default
--chaos-duration Set chaos duration (in secs) as desired number No 60
--cores Number of cores (workers) of node CPU to be consumed number No
--cpu-percentage Percentage of total cpu to be consumed number No 50
--namespace Namespace where the scenario container will be deployed string No default
--node-selector Node selector where the scenario containers will be scheduled in the format “=”. NOTE: Will be instantiated a container per each node selected with the same scenario options. If left empty a random node will be selected string No
--taints List of taints for which tolerations need to be created. For example [“node-role.kubernetes.io/master:NoSchedule”]" string No []
--number-of-nodes restricts the number of selected nodes by the selector number No
--image The hog container image. Can be changed if the hog image is mirrored on a private repository string No quay.io/krkn-chaos/krkn-hog

To see all available scenario options

krknctl run node-cpu-hog --help

Demo

See a demo of this scenario: