> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/resilience-testing/chaos-engineering/faults/chaos-fault-categories/kubernetes/pod/pod-jvm-memory-stress.md).

# Pod JVM memory stress

Pod JVM memory stress injects JVM memory stress for a Java process executing in a Kubernetes pod by consuming excessive memory resources of the JVM. This sometimes results in an OOM kill (Out-of-memory).

{% hint style="info" %}
JVM chaos faults use the [Byteman utility](https://byteman.jboss.org/) to inject chaos faults into the JVM.
{% endhint %}

#### Use cases <a href="#use-cases" id="use-cases"></a>

Pod JVM memory stress:

* Tests the system's ability to handle high payloads.
* Evaluates the application's behavior in high-stress cases.
* Induces memory consumption and exhaustion on the target Java process JVM executing in a K8s pod.
* Simulates a lack of memory for processes running on the application, which degrades their performance.
* Simulates application slowness due to memory starvation, and noisy neighbour problems due to excessive consumption of memory.

#### Permissions required <a href="#permissions-required" id="permissions-required"></a>

Below is a sample Kubernetes role that defines the permissions required to execute the fault.

```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: hce
  name: pod-jvm-memory-stress
spec:
  definition:
    scope: Namespaced
permissions:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["create", "delete", "get", "list", "patch", "deletecollection", "update"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["create", "get", "list", "patch", "update"]
  - apiGroups: [""]
    resources: ["pods/log"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["deployments", "statefulsets"]
    verbs: ["get", "list"]
  - apiGroups: ["batch"]
    resources: ["jobs"]
    verbs: ["create", "delete", "get", "list", "deletecollection"]
```

{% hint style="info" %}
**JAVA REQUIREMENTS**

This fault requires the following Java-specific prerequisites:

* The Java process must allow agent attachment (Attach API must be available).
* Utilities like `ps`, `pgrep`, and `bash` must be available in the target container.
* File permissions must allow the JVM to read and execute agent files.
* Agent attachment must not be restricted by user or security context configurations.
* The target container image must not use a restricted/minimal Java runtime that removes attach-related modules.
  {% endhint %}

#### Supported environments <a href="#supported-environments" id="supported-environments"></a>

| Platform                                | Support Status |
| --------------------------------------- | -------------- |
| GKE (Google Kubernetes Engine)          | ✅ Supported    |
| EKS (Amazon Elastic Kubernetes Service) | ✅ Supported    |
| AKS (Azure Kubernetes Service)          | ✅ Supported    |
| GKE Autopilot                           | ✅ Supported    |
| Self-managed Kubernetes                 | ✅ Supported    |

#### Optional tunables <a href="#optional-tunables" id="optional-tunables"></a>

| Tunable                   | Description                                                                                                                                             | Notes                                                                                                                                                                                                                                                                                                                |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| MEMORY\_TYPE              | The type of JVM memory region to stress.                                                                                                                | Default: `heap`. Choose between heap and stack.                                                                                                                                                                                                                                                                      |
| TOTAL\_CHAOS\_DURATION    | Duration through which chaos is injected into the target resource. Should be provided in `[numeric-hours]h[numeric-minutes]m[numeric-seconds]s` format. | Default: `30s`. Examples: `1m25s`, `1h3m2s`, `1h3s`. For more information, go to [duration of the chaos.](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/common-tunables-for-all-faults.md#duration-of-the-chaos)                                                                               |
| POD\_AFFECTED\_PERCENTAGE | Percentage of total pods to target. Provide numeric values.                                                                                             | Default: 0 (corresponds to 1 replica). For more information, go to [pods affected percentage](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/kubernetes/pod/common-tunables-for-pod-faults.md#pod-affected-percentage)                                                                          |
| JAVA\_HOME                | Path to the Java installation directory.                                                                                                                | For example, /tmp/dir/jdk.                                                                                                                                                                                                                                                                                           |
| BYTEMAN\_PORT             | Port used by the Byteman agent.                                                                                                                         | Default: `9091`.                                                                                                                                                                                                                                                                                                     |
| CONTAINER\_RUNTIME        | Container runtime interface for the cluster                                                                                                             | Default: containerd. Support values: docker, containerd and crio. For more information, go to [container runtime](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/kubernetes/pod/pod-api-modify-body.md#container-runtime-and-socket-path).                                                      |
| SOCKET\_PATH              | Path of the containerd or crio or docker socket file.                                                                                                   | Default: `/run/containerd/containerd.sock`. For more information, go to [socket path](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/kubernetes/pod/pod-api-modify-body.md#container-runtime-and-socket-path).                                                                                  |
| RAMP\_TIME                | Period to wait before and after injecting chaos. Should be provided in `[numeric-hours]h[numeric-minutes]m[numeric-seconds]s` format.                   | Default: `0s`. Examples: `1m25s`, `1h3m2s`, `1h3s`. For more information, go to [ramp time.](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/common-tunables-for-all-faults.md#ramp-time)                                                                                                        |
| SEQUENCE                  | Sequence of chaos execution for multiple target pods.                                                                                                   | Default: parallel. Supports serial and parallel. For more information, go to [sequence of chaos execution](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/common-tunables-for-all-faults.md#sequence-of-chaos-execution).                                                                       |
| TARGET\_CONTAINER         | Name of the target container subject to chaos.                                                                                                          | None. For more information, go to [target specific container](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/kubernetes/pod/common-tunables-for-pod-faults.md#target-specific-container)                                                                                                        |
| TARGET\_PODS              | Comma-separated list of application pod names subject to pod JVM memory stress.                                                                         | If not provided, the fault selects target pods randomly based on provided appLabels. For more information, go to [target specific pods](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/kubernetes/pod/common-tunables-for-pod-faults.md#target-specific-pods).                                  |
| NODE\_LABEL               | Node label used to filter the target node if `TARGET_NODE` environment variable is not set.                                                             | It is mutually exclusive with the `TARGET_NODE` environment variable. If both are provided, the fault uses `TARGET_NODE`. For more information, go to [node label.](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/kubernetes/node/common-tunables-for-node-faults.md#target-nodes-with-labels) |
| LIB\_IMAGE                | Image used to inject chaos.                                                                                                                             | Default: `harness/chaos-go-runner:main-latest`. For more information, go to [image used by the helper pod.](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/common-tunables-for-all-faults.md#image-used-by-the-helper-pod)                                                                      |

#### Memory type <a href="#memory-type" id="memory-type"></a>

The type of memory that is consumed in excess by the JVM; choose between **heap** and **stack** memory.

The following YAML snippet illustrates the use of this input variable.

```yaml
apiVersion: litmuschaos.io/v1alpha1
kind: KubernetesChaosExperiment
metadata:
  name: pod-jvm-memory-stress
  namespace: hce
spec:
  tasks:
     - definition:
        chaos:
          env:
            # type of memory to stress: heap or stack
            - name: MEMORY_TYPE
              value: "heap"
            - name: TOTAL_CHAOS_DURATION
              value: "60"
```

#### Parameters <a href="#parameters" id="parameters"></a>

The following YAML snippet illustrates the use of these tunables.

```yaml
apiVersion: litmuschaos.io/v1alpha1
kind: KubernetesChaosExperiment
metadata:
  name: pod-jvm-memory-stress
  namespace: hce
spec:
  tasks:
     - definition:
        chaos:
          env:
            - name: TOTAL_CHAOS_DURATION
              value: "60"
            - name: POD_AFFECTED_PERCENTAGE
              value: ""
            - name: BYTEMAN_PORT
              value: "9091"
            - name: JAVA_HOME
              value: ""
            - name: MEMORY_TYPE
              value: "heap"
            - name: CONTAINER_RUNTIME
              value: containerd
            - name: SOCKET_PATH
              value: /run/containerd/containerd.sock
            - name: LIB_IMAGE
              value: docker.io/harness/chaos-ddcr-faults:1.49.2
            - name: RAMP_TIME
              value: ""
            - name: SEQUENCE
              value: parallel
            - name: TARGET_CONTAINER
              value: ""
            - name: TARGET_PODS
              value: ""
            - name: NODE_LABEL
              value: ""
```
