I feel like I am misunderstanding RAM based emptyDir
volumes in Kubernetes.
Let's suppose my Kubernetes node has a total of 100GB. If I have 4 different emptyDirs that have emptyDir.medium
set to "Memory", by default will they all have 50GBs of memory? In that case what happens when the total amount of memory used in my 4 emptyDirs exceeds 100GB?
I know in general RAM is fast, but what are some examples for the downsides? From the official documentation, I see the below but I don't quite understand the statement. My understanding is that if a Pod crashes, files on emptyDirs using disk will still be deleted. Will the files be kept upon node reboot if they are stored in disk? Also what do they mean by count against container memory limit
?
While tmpfs is very fast, be aware that unlike disks,
tmpfs is cleared on node reboot and any files you
write count against your container's memory limit
...by default will they all have 50GBs of memory?
Yes. You can exec into the pod and check with df -h
. If your cluster has SizeMemoryBackedVolumes
feature enabled, you can specify the size.
...what happens when the total amount of memory used in my 4 emptyDirs exceeds 100GB?
You won't get that chance because the moment the total amount of memory used by all emptyDir(s) reach 50GB; your pod will be evicted. It doesn't need a single emptyDir to reach 50GB to evict.
...don't quite understand the statement.
It means you will not get back the data storing on emptyDir.
count against container memory limit
It means the amount of memory that you consumed using emptyDir is added to the amount of the memory that your container used and check against the resources.limits.memory.
Same documentation page:
When a Pod is removed from a node for any reason, the data in the emptyDir is deleted permanently.
Note: A container crashing does not remove a Pod from a node. The data in an emptyDir volume is safe across container crashes.
So pod crash does not cause emptyDir
volume to be cleared.
Regarding general usage of memory backed volumes: always specify pod memory limit otherwise you may face surprises like various counter-intuitive pod evictions.
Also if you're planning to actively write to memory backed volume (that's what memory is for) you need to carefully control how much data is written otherwise you may face strange application crashes.