Create Pressure on Kubernetes Nodes

5/10/2020

I want to test Pod eviction events that caused by memorypressure for taintbasedeviction on my pods, for to do that I created a memory load on my instance that have 2 vcpu and 8GB Ram.

For create a load I have run this command :

stress-ng --vm 2 --vm-bytes 10G --timeout 60s

Output of memory usage

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.8Gi       2.7Gi       1.0Gi       3.9Gi       4.1Gi       984Mi
Swap:            0B          0B          0B

But in my nodes states there is no memorypressure I have updated kubelet eviction parameters at below :

evictionHard:
    memory.available:  "200Mi"

As summary, How Can I create memory pressure on my worker nodes for test the taint based eviction ?

Thanks

-- Ayhan Balik
containers
kubernetes
linux

1 Answer

5/10/2020

You could invoke the stress command multiple times. Check the script here.

The value for memory.available is derived from the cgroupfs instead of tools like free -m. This is important because free -m does not work in a container, and if users use the node allocatable feature, out of resource decisions are made local to the end user Pod part of the cgroup hierarchy as well as the root node. This script reproduces the same set of steps that the kubelet performs to calculate memory.available. The kubelet excludes inactive_file (i.e. # of bytes of file-backed memory on inactive LRU list) from its calculation as it assumes that memory is reclaimable under pressure.

-- Arghya Sadhu
Source: StackOverflow