1.8 KiB
1.8 KiB
📦 Pod Volume Lifecycle & emptyDir Usage in Kubernetes
This document describes how volumes work in the context of Kubernetes Pods, focusing on emptyDir and its lifecycle behavior.
🔁 Pod Lifecycle & Volumes
-
Volumes are defined at the Pod level. They are not tied to a specific container, but can be shared among containers within the same Pod.
-
Volumes are attached to containers through
volumeMounts. This enables containers to access the volume’s filesystem at the specifiedmountPath. -
Data in
emptyDirvolumes is ephemeral. The volume is created when the Pod starts and deleted when the Pod is removed, erasing all stored data.
⚠️ Visibility Across Pods & Containers
-
A Pod cannot access another Pod’s volume, even if it's of type
emptyDir. For example:- Pod A cannot see Pod B’s
emptyDir.
- Pod A cannot see Pod B’s
-
However, containers within the same Pod can share and access the same
emptyDirvolume.
🧪 Example: Pod with emptyDir Volume in Memory
apiVersion: v1
kind: Pod
metadata:
namespace: ns-test
name: pod-tests
spec:
containers:
- name: nginx
image: nginx
resources:
limits:
memory: "150Mi"
cpu: "500m"
volumeMounts:
- name: nginx-log
mountPath: /var/log/nginx
volumes:
- name: nginx-log
emptyDir:
medium: Memory # Uses memory for faster read/write operations
sizeLimit: 64Mi # Volume size limited to 64Mi
🧠 Key Points
emptyDiris ideal for temporary storage like logs, scratch space, or caches.- Using
medium: Memorystores data in memory (RAM) instead of disk, offering higher performance. sizeLimitrestricts the amount of memory that theemptyDircan consume.