Kubernetes Pod Ephemeral Storage
The Ephemeral Storage available to a Kubernetes Pod comes in two forms: one that uses the Node’s Storage and one that uses the Node’s Memory. The Pod’s configuration and behavior differ depending on which storage is used.
1. Ephemeral Storage based on Node Storage
Ephemeral Storage based on Node Storage is used by a Pod for the following purposes.
- Container Writable Layer
- Container Log (stdout, stderr)
emptyDirVolume whose Medium is not theMemoryType
| |
Ephemeral Storage based on Node Storage can be configured through the ephemeral-storage field of the Pod Resource. [File 1] shows an example of the my-shell-storage Pod that configures Ephemeral Storage based on Node Storage. The my-shell Container sets 1Gi as the Request and 2Gi as the Limit. An emptyDir Volume named emptydir-storage is also configured, and its size is limited to 512Mi.
The Ephemeral Storage of the Request is referenced only when the Scheduler schedules the Pod, while the Ephemeral Storage of the Limit means the maximum size the Container can actually use. Therefore, if the total Ephemeral Storage size of the my-shell Container’s Container Writable Layer, Container Log, and emptyDir Volume exceeds 4Gi, the Pod is Evicted. The Pod is also Evicted if the size of the emptydir-storage Volume exceeds 512Mi.
| |
[Shell 1] shows the result of mounting the emptydir-storage Volume in the my-shell-storage Pod. It can be seen that the Node’s Storage is Bind Mounted.
| |
| |
[Shell 2] shows the case where the Pod is Evicted because the Ephemeral Storage of the my-shell-storage Pod exceeds 2Gi, and [Shell 3] shows the case where the Pod is Evicted because the emptydir-storage Volume of the my-shell-storage Pod exceeds 512Mi. The usage of Ephemeral Storage based on Node Storage is measured periodically by the kubelet. Therefore, the moment the Node Storage based Ephemeral Storage used by the Pod exceeds the Limit, the Pod is not Evicted immediately and can exist for a certain period of time. In general, it can exist for about 30 to 40 seconds after the capacity is exceeded.
2. Ephemeral Storage based on Node Memory
Ephemeral Storage based on Node Memory is used for the following single purpose.
emptyDirVolume with theMemoryType Medium
| |
[File 2] shows an example of the my-shell-memory Pod that configures Ephemeral Storage based on Node Memory. The my-shell Container uses an emptyDir Volume named emptydir-memory, which has a size of 512Mi and is configured with the Memory Type as its medium Type.
An emptyDir Volume of the Memory Type is included in the Container’s Memory usage. Therefore, the Container’s Memory Request and Limit must be set larger than the capacity of the emptyDir Volume, and must also be set considering the Memory size to be used by the App inside the Container. In the case of [File 2], since the emptydir-memory Volume is 512Mi, the Memory size available to the App inside the Container is at least 1Gi - 512Mi = 512Mi based on the Request, and at least 2Gi - 512Mi = 1.5Gi based on the Limit.
| |
[Shell 4] shows the result of mounting the emptydir-memory Volume in the my-shell Container of the my-shell-memory Pod. It can be seen that a tmpfs Type Volume is mounted at /tmp. The size of the tmpfs Volume is confirmed to be 512Mi. In other words, inside the Pod, capacity cannot be used beyond the size of the tmpfs Volume. Since Ephemeral Storage based on Node Storage checks capacity periodically, a temporary capacity excess can occur. This can cause the Pod to be Evicted, but Ephemeral Storage based on Node Memory limits the tmpfs size, so a temporary capacity excess does not occur.
| |
As shown in [File 3], it is possible not to set a capacity limit on an emptyDir Volume with the Memory Medium, and in this case, it can be used up to the size of the Container’s Memory Limit. In the case of [File 3], since the Limit Memory of the my-shell Container is 2Gi, up to 2Gi of capacity can be used. If no Memory Limit is set on the Container, it can be used up to the size of the Node’s Memory.
However, using all of the Node’s Memory can affect other Pods running on that Node, so it is not a recommended approach. Therefore, to safely use an emptyDir Volume with the Memory Medium, the Container’s Memory Limit must be set or the capacity of the emptyDir Volume must be limited.
| |
[Shell 5] shows the result of mounting the emptydir-memory Volume in the my-shell Container of the my-shell-memory-no-limit Pod. It can be seen that a tmpfs Type Volume is mounted at /tmp and its size is 16Gi. Here, 16Gi is the Memory size of the Node, and since the capacity of the emptyDir Volume was not limited, it is set to the Node’s Memory size.
2.1. Limiting Shared Memory Capacity
| |
Setting an emptyDir Volume with the Memory Medium at the /dev/shm path makes it possible to limit the size of the Shared Memory used by the App. [File 4] shows an example of the my-shell-memory-shm Pod that limits the size of the Shared Memory. Since the size of the emptyDir Volume is limited to 512Mi, the size of the Shared Memory is also limited to 512Mi.
3. References
- Ephemeral Storage : https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#local-ephemeral-storage
- Kubernetes Shared Memory : https://ykarma1996.tistory.com/106