Sub topic 13
Ephemeral Storage Requests and Limits
This chapter assumes you can write pod manifests and apply them with kubectl. It also assumes you know how CPU and memory requests and limits work, from the earlier chapters on units, scheduling and OOM kills. Here the same model is applied to a third resource, ephemeral storage.
What ephemeral storage is
Ephemeral storage is the node-local disk space a pod uses and loses when the pod is removed. A pod consumes it in three main ways:
- Writes to the container's writable layer, such as files created in the container filesystem.
- Logs written by the container runtime to the node.
emptyDirvolumes, except those backed by memory (medium: Memory), which count against memory instead.
Persistent volumes are not ephemeral storage. They have their own capacity and are not covered by these settings.
Without limits, a single pod that writes too much can fill the node disk. That causes disk pressure and affects every pod on the node.
Setting the request and limit
Ephemeral storage uses the resource name ephemeral-storage. It takes the same quantity suffixes as memory: Mi, Gi, or plain bytes. Do not use m, which is meant for CPU.
apiVersion: v1
kind: Pod
metadata:
name: scratch-writer
spec:
containers:
- name: app
image: busybox:1.36
command: ["sh", "-c", "sleep 3600"]
resources:
requests:
ephemeral-storage: 1Gi
limits:
ephemeral-storage: 2Gi
volumeMounts:
- name: scratch
mountPath: /scratch
volumes:
- name: scratch
emptyDir:
sizeLimit: 500MiThe request and the limit do different jobs, as with the other resources.
| Setting | Effect |
|---|---|
| `requests.ephemeral-storage` | The scheduler only places the pod on a node with enough unreserved allocatable ephemeral storage. |
| `limits.ephemeral-storage` | The kubelet evicts the pod if its usage exceeds the limit. |
| `emptyDir.sizeLimit` | The kubelet evicts the pod if that volume grows past the size limit. |
What happens when a pod goes over
Storage behaves differently from both CPU and memory. It cannot be throttled, and the kernel does not kill the container for exceeding it. Instead, the kubelet checks usage periodically. If the pod's total exceeds the limit, the kubelet evicts the whole pod. The pod then shows a status of Evicted, and the reason in its status message mentions ephemeral local storage.
Because the kubelet checks on an interval, a pod can briefly exceed its limit before it is evicted. The limit is not a hard cap enforced at write time.
Defaults and quotas
The same namespace tools apply. A LimitRange can set defaultRequest and default for ephemeral-storage under type: Container. A ResourceQuota can cap the namespace total with requests.ephemeral-storage and limits.ephemeral-storage.
apiVersion: v1
kind: ResourceQuota
metadata:
name: team-a-storage
namespace: team-a
spec:
hard:
requests.ephemeral-storage: 20Gi
limits.ephemeral-storage: 40GiOnce a quota covers ephemeral-storage, new pods in that namespace must declare it or be rejected, unless a LimitRange supplies defaults.
Common errors
- Using the wrong suffix.
500mmeans 0.5 bytes for storage, which is almost never what you want. Write500Mi. - Forgetting logs. Container logs count toward usage. A chatty application can reach its limit without writing any files.
- Pending with insufficient ephemeral-storage. The
FailedSchedulingevent names the resource. Lower the request or add node capacity. - Expecting a restart in place. An eviction removes the pod. A Deployment creates a replacement, but the container is not restarted inside the old pod.
To check for the problem, run kubectl describe pod and read the status message and events. To see the node's allocatable storage, run kubectl describe node and look under Allocatable.
Exercise
A container has limits.ephemeral-storage: 1Gi and writes 2 GiB of logs and temporary files. Is it throttled, OOM-killed, or something else? What does the pod's status show afterward?
Show answer
It is neither. The kubelet notices that the pod's ephemeral storage usage is over the limit and evicts the whole pod. The status shows Evicted, with a message about exceeding the ephemeral local storage limit. Because the kubelet checks periodically, the usage can briefly pass 1Gi before the eviction happens.
Exercise
Why does ephemeral-storage: 500m almost certainly not do what the author intended?
Show answer
The m suffix means milli-units, so 500m is 0.5 bytes. For storage, use binary suffixes such as 500Mi.