If pod dies data can die with it. While containers are alive they need to share some data.

eksctl create cluster --name pv-cluster --region ap-south-1 --nodes 3 --node-type t2.medium
manifest.yml
apiVersion: apps/v1
kind: Deployment # Starting a deployment
metadata:
name: shared-data-deployment
spec:
replicas: 1
selector:
matchLabels:
app: shared-data-pod # All pods labelled with it , will be part of this deployment
template:
metadata:
labels:
app: shared-data-pod # Attching label to pod
spec:
containers:
- name: writer # This container writes to shared-data
image: busybox # Process that's running infinitely
command: ["/bin/sh","-c","echo 'Hello from writer container' > /data/hello.txt; sleep 3600" ] # Run a shell command writes `Hello..' to /data/hello.txt every 1 hr
volumeMounts: # In this container I want this volume to be mounted at mountPath
- name: shared-data
mountPath: /data
- name: reader
image: busybox
command: ["/bin/sh","-c","cat /data/hello.txt; sleep 3600"] # Read from /data every 1hr
volumeMounts:
- name: shared-data
mountPath: /data
volumes: # Describe volumes that containers have access to
- name : shared-data
emptyDir: {} # Type of volume
kubectl apply -f manifest.yml
# ssh into writer container and check if data is written to /data/hello.txt
kubectl exec -it shared-data-deployment-69fb8d7c8d-jx4xq -c writer -- sh
# Check the logs of reader container to see if data gets logged
kubectl logs -f shared-data-deployment-69fb8d7c8d-jx4xq - reader


You can see the data is written in writer container and read by reader container i.e sharing of data by 2 containers inside same pod is happening
/data in one container lets say writer the same file will be automatically created inside reader container that means both containers are sharing volume shared-data
