You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+47-8
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,15 @@ To use the `k8s-pod-cpu-stressor`, you need to have the following installed:
46
46
go build -o cpu-stress .
47
47
```
48
48
49
+
### Applying Sample Manifests
50
+
51
+
To quickly apply the sample Kubernetes manifests, navigate to the `k8s-manifests` folder and run the following command:
52
+
53
+
```shell
54
+
kubectl apply -f deployment.yaml
55
+
kubectl apply -f job.yaml
56
+
```
57
+
49
58
## Running with Docker
50
59
51
60
Build the Docker image using the provided Dockerfile:
@@ -54,13 +63,13 @@ Build the Docker image using the provided Dockerfile:
54
63
docker build -t k8s-pod-cpu-stressor .
55
64
```
56
65
57
-
Run the Docker container, specifying the desired CPU usage, stress duration, and optionally whether to run CPU stress indefinitely:
66
+
Run the Docker container, specifying the desired CPU usage, stress duration, memory usage, memory stress duration, and optionally whether to run CPU and memory stress indefinitely:
58
67
59
68
```shell
60
-
docker run --rm k8s-pod-cpu-stressor -cpu=0.2 -duration=10s -forever
69
+
docker run --rm k8s-pod-cpu-stressor -cpu=0.2 -duration=10s -forever -memory=0.2 -memduration=10s -memforever
61
70
```
62
71
63
-
Replace `0.2` and `10s` with the desired CPU usage (fraction)and duration, respectively. Add `-forever`flag to run CPU stress indefinitely.
72
+
Replace `0.2` and `10s` with the desired CPU usage (fraction), duration, memory usage (fraction), and memory stress duration, respectively. Add `-forever`and `-memforever` flags to run CPU and memory stress indefinitely.
64
73
65
74
## CPU Usage and Duration
66
75
@@ -72,14 +81,24 @@ The `k8s-pod-cpu-stressor` allows you to specify the desired CPU usage and stres
72
81
73
82
-**Run Indefinitely**: To run CPU stress indefinitely, include the `-forever` flag.
74
83
75
-
Adjust these parameters according to your requirements to simulate different CPU load scenarios.
84
+
## Memory Usage and Duration
85
+
86
+
The `k8s-pod-cpu-stressor` also allows you to specify the desired memory usage and stress duration using the following parameters:
87
+
88
+
-**Memory Usage**: The memory usage is defined as a fraction of memory resources. It is specified using the `-memory` argument. For example, `-memory=0.2` represents a memory usage of 20%.
89
+
90
+
-**Memory Stress Duration**: The memory stress duration defines how long the memory stress operation should run. It is specified using the `-memduration` argument, which accepts a duration value with a unit. Supported units include seconds (s), minutes (m), hours (h), and days (d). For example, `-memduration=10s` represents a memory stress duration of 10 seconds, `-memduration=5m` represents 5 minutes, `-memduration=2h` represents 2 hours, and `-memduration=1d` represents 1 day.
91
+
92
+
-**Run Memory Stress Indefinitely**: To run memory stress indefinitely, include the `-memforever` flag.
93
+
94
+
Adjust these parameters according to your requirements to simulate different CPU and memory load scenarios.
76
95
77
96
### Kubernetes Resource Requests and Limits
78
97
79
-
It is recommended to specify Kubernetes resource requests and limits to control the amount of CPU resources consumed by the pod, and to prevent overloading your cluster. For example:
98
+
It is recommended to specify Kubernetes resource requests and limits to control the amount of CPU and memory resources consumed by the pod, and to prevent overloading your cluster. For example:
80
99
81
-
-**Requests**: This defines the minimum amount of CPU that the pod is guaranteed to have.
82
-
-**Limits**: This defines the maximum amount of CPU that the pod can use.
100
+
-**Requests**: This defines the minimum amount of CPU and memory that the pod is guaranteed to have.
101
+
-**Limits**: This defines the maximum amount of CPU and memory that the pod can use.
83
102
84
103
Adding requests and limits helps Kubernetes manage resources efficiently and ensures that your cluster remains stable during stress testing.
85
104
@@ -89,8 +108,10 @@ Example:
89
108
resources:
90
109
requests:
91
110
cpu: "100m"
111
+
memory: "128Mi"
92
112
limits:
93
113
cpu: "200m"
114
+
memory: "256Mi"
94
115
```
95
116
96
117
## Check the Public Docker Image
@@ -127,16 +148,21 @@ spec:
127
148
- "-cpu=0.2"
128
149
- "-duration=10s"
129
150
- "-forever"
151
+
- "-memory=0.2"
152
+
- "-memduration=10s"
153
+
- "-memforever"
130
154
resources:
131
155
limits:
132
156
cpu: "200m"
157
+
memory: "256Mi"
133
158
requests:
134
159
cpu: "100m"
160
+
memory: "128Mi"
135
161
```
136
162
137
163
## Sample Job Manifest
138
164
139
-
If you want to run the CPU stressor for a fixed duration as a one-time job, you can use the following Kubernetes Job manifest:
165
+
If you want to run the CPU and memory stressor for a fixed duration as a one-time job, you can use the following Kubernetes Job manifest:
140
166
141
167
```yaml
142
168
apiVersion: batch/v1
@@ -155,17 +181,30 @@ spec:
155
181
args:
156
182
- "-cpu=0.5"
157
183
- "-duration=5m"
184
+
- "-memory=0.5"
185
+
- "-memduration=5m"
158
186
resources:
159
187
limits:
160
188
cpu: "500m"
189
+
memory: "512Mi"
161
190
requests:
162
191
cpu: "250m"
192
+
memory: "256Mi"
163
193
restartPolicy: Never
164
194
backoffLimit: 3
165
195
```
166
196
167
197
This manifest runs the `k8s-pod-cpu-stressor` as a Kubernetes Job, which will execute the stress test once for 5 minutes and then stop. The `backoffLimit` specifies the number of retries if the job fails.
168
198
199
+
## Sample Kubernetes Manifests
200
+
201
+
You can find sample Kubernetes manifests in the `k8s-manifests` folder. These manifests include deployment and job configurations for the `k8s-pod-cpu-stressor`. To quickly apply these manifests, navigate to the `k8s-manifests` folder and run the following command:
202
+
203
+
```shell
204
+
kubectl apply -f deployment.yaml
205
+
kubectl apply -f job.yaml
206
+
```
207
+
169
208
## Contributing
170
209
171
210
Contributions are welcome! If you find a bug or have a suggestion, please open an issue or submit a pull request. For major changes, please discuss them first in the issue tracker.
0 commit comments