How to use ephemeral storage?
· Category: Kubernetes
Short answer
Ephemeral storage is temporary storage tied to the Pod lifecycle. The most common type is emptyDir, which creates an empty directory when the Pod starts and deletes it when the Pod terminates.
Steps
- Define an
emptyDirvolume in the Pod spec. - Mount it into the container.
- Optionally set storage requests and limits.
Example
apiVersion: v1
kind: Pod
metadata:
name: temp-worker
spec:
containers:
- name: worker
image: busybox
volumeMounts:
- name: scratch
mountPath: /scratch
resources:
requests:
ephemeral-storage: "1Gi"
limits:
ephemeral-storage: "2Gi"
volumes:
- name: scratch
emptyDir: {}
Tips
- Use
emptyDirfor caching, temporary processing, and shared scratch space between containers. - Use
medium: Memoryfor a RAM-backed tmpfs. - Monitor ephemeral storage usage to prevent eviction.
Common issues
- Exceeding ephemeral storage limits causes Pod eviction.
- Node disk pressure can trigger mass evictions.
emptyDirdata is lost on Pod restart.