The stress command is a tool for generating workload and stress test on a Linux system. It can be used to simulate high CPU, memory, and I/O usage to test the stability and performance of the system.
Installation:
sudo yum install stress -y
After this we have to find the number of cores inside the Linux operating system.
To fetch the cores information from the Linux operating system use the below command as shown in the below:
/proc/cpuinfo = Related to the cpu information.
grep processor = search the processor in file
wc –l = no of word lines count in file.
Without timeout use the below command as shown in the below:
stress --cpu 4 --io 2 --vm 2 --vm-bytes 512M
--cpu 4 will stress 4 CPUs at 100% load.
--io 2 will generate two I/O operations per worker thread.
--vm 2 will create two worker threads for stressing the memory.
--vm-bytes 512M will allocate 512 megabytes of memory per worker thread.
To check the command output go in to the duplication of the same server and check with the top command as shown in the below:
top
If you want to check with the timeout option use the below command as shown in the below way:
stress --cpu 4 --io 2 --vm 2 --vm-bytes 512M --timeout 60s
First of all create the target pod yaml file as shown in the below
apiVersion: v1
kind: Pod
metadata:
name: nginx-stress
spec:
containers:
- name: nginx
image: ubuntu/nginx
ports:
- containerPort: 80
- name: stress
image: progrium/stress
command: ["stress", "--cpu", "2", "--io", "1", "--vm", "1", "--vm-bytes", "128M", "--timeout", "60s"]
By using this yaml create the pod as shown in the below:
kubectl apply -f stress.yaml
kubectl get all --all-namespaces
If you will see in the above output the nginx-stress pod is running successfully whatever the yaml file we have created.
kubectl describe pod/nginx-stress -n default
Here we have applied two containers in one pod like nginxand stress containers in manifest stress.yaml after applying the file the pod is created and running successfully.
Due to the stress involvement in the manifest file the pod is getting automatically getting down.
Check if there are any events related to the pod that indicate stress or errors, such as CrashLoopBackOff, Failed, or Error. This is the indication that our stress commands are working successfully.
Kubectl get pods
We have created stress manifest and nginx file with the timeout 60s so it is randomly running for 60s and getting down for 60s as shown in the above images. If you will observe in the above output due to stress it was varying.
The stress here is applied successfully.
Thank you!
Author's name: Sridhar Modalavalasa
DevOps Engineer