Kubernetes 101 : Sharing a directory between containers in the same pod - emptyDir -

Some applications might need to use a shared directory to share data with another container in the same pod.

The shared data might be logs, analytics, ...

The below diagrams gives us an idea about the shared volume "emptyDir".

The "shared-volume" is located somewhere in the kubelet root directory on the host "/var/lib/kubelet".

Below is the Yaml file for the "pod-emptyDir" pod:

We create our pod using the below command:

We list our pods using the below command:

We get inside the nginx container using the below command:

The "kubectl exec" command executes the command "/bin/bash" inside the "nginx" container interactively "-it".

We could create files in the "shared-vol-nginx" directoy that could be accessed from the "debian" container in its "/shared-vol-debian" directory.


The shared volume emptyDir is removed when the pod exits.


Leave as a comment: