Shared Pod storage
A volume such as emptyDir can be mounted into multiple containers so they see the same files.
Use shared Pod volumes so multiple containers in the same Pod can exchange files without network calls.
k8s/labs/storage/data-sharing.yaml — Multi-container Pod sharing data via emptyDirA volume such as emptyDir can be mounted into multiple containers so they see the same files.
File sharing inside one Pod avoids the overhead of exposing a separate service between helper containers.
With emptyDir, data exists for the Pod lifecycle, which is often exactly what helper workflows need.
The Pod defines an emptyDir or another shared volume resource.
Each container mounts the same volume path into its own filesystem.
A helper or generator container creates files in the shared path.
The second container consumes the same files without any extra networking layer.
emptyDir PodapiVersion: v1
kind: Pod
metadata:
name: data-sharing-pod
spec:
containers:
- name: app-container-1
image: nginx
volumeMounts:
- mountPath: /usr/share/nginx/html
name: shared-data
- name: app-container-2
image: busybox
command: ["/bin/sh", "-c", "echo Shared data from app-container-2 > /usr/share/nginx/html/index.html && sleep 3600"]
volumeMounts:
- mountPath: /usr/share/nginx/html
name: shared-data
volumes:
- name: shared-data
emptyDir: {}
| Pattern | Persistence | Use Case |
|---|---|---|
| emptyDir | Pod lifecycle only | Temporary sharing, caches, generated content |
| ConfigMap volume | Externally defined config data | Shared configuration files |
| PVC | Persistent beyond Pod deletion | Shared state that must survive recreation |
emptyDir when you want collaboration, not durability.One container writes logs while another ships or analyzes them.
Create content in one container and serve it from another container in the same Pod.
Pass artifacts through shared local files without adding extra services or persistence.