Containers in a Pod do not share a filesystem. To pass files between them, give the Pod a volume and mount it in both.
emptyDir
An emptyDir is a directory created empty when the Pod starts and deleted when the Pod goes. It survives a container restart; it does not survive the Pod.
shared: emptyDirspec.volumes → /workwriter mounts it at and /usr/share/nginx/htmlweb mounts it at
yaml
spec:
volumes:
- name: shared
emptyDir: {}
containers:
- name: writer
image: busybox
command: ["sh", "-c", "echo '<h1>Monster Market</h1>' > /work/index.html; sleep 3600"]
volumeMounts:
- name: shared
mountPath: /work
- name: web
image: nginx:1.27
volumeMounts:
- name: shared
mountPath: /usr/share/nginx/htmlwriter writes /work/index.html. web serves the same file as /usr/share/nginx/html/index.html. One directory, two names.
text
learner@shallows:~$ kubectl exec pair -c web -- ls /usr/share/nginx/html
index.html
learner@shallows:~$ kubectl exec pair -c writer -- ls /work
index.htmlTwo fields
| Field | Where | Says |
|---|---|---|
volumes | Pod spec, once | This volume exists, and what backs it |
volumeMounts | Each container | Where this container sees it |
A container without a volumeMounts entry for the volume does not see it at all.