I have dirctory on K8
master server.
I have 20 pods (With Deployment replicas).
I want all pods read from master directory /path/in/master/infiles
And write their output to same directory /path/in/master/outfiles
, Which Volume type should I need to use at this case? I Want my files not deleted after pod die.
I trying to look at the following: https://kubernetes.io/docs/concepts/storage/volumes/ but still don't know what is the best options for my case.
Any suggestions?
You can use hostPath volume.
A hostPath
volume mounts a file or directory from the host node’s filesystem into your Pod.
apiVersion: v1
kind: PersistentVolume
metadata:
name: task-pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
hostPath:
path: "/path/in/master/infiles"
Check this guide on how to use hostPath.
A better option would be to use local volume.
apiVersion: v1
kind: PersistentVolume
metadata:
name: example-pv
spec:
capacity:
storage: 100Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
path: "/path/in/master/infiles"
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- example-node
Compared to hostPath volumes, local volumes can be used in a durable and portable manner without manually scheduling Pods to nodes, as the system is aware of the volume’s node constraints by looking at the node affinity on the PersistentVolume.
Edit:
The problem with storing data in the filesystem of the nodes itself is that there is no way to sync the data between the nodes. If this is needed for the application then using a PV backed by NFS in ReadWriteMany(RWX) mode is a better option. Here is guide on how to make this work in digital ocean.