I am new to Kubernetes, so maybe a silly question.
I am trying to deploy statefulset of ElasticSearch with 3 pod replicas. I have defined Statefulset with pvc in spec.
This pvc has storage class which is served by a hostPath volume.
volumeClaimTemplates:
- metadata:
name: beehive-pv-claim
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "local-storage"
resources:
requests:
storage: 1Gi
apiVersion: v1
kind: PersistentVolume
metadata:
name: beehive-pv
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
hostPath:
path: /home/abc
I have few doubts.
1) Would above setup/pv serve /host/abc directory on each node separately? i.e. every pod data would be stored on its corresponding node/host path. Also, wouuld k8s show one volume bound to multiple pvc?
2) As I am using statefulset, I am assuming that the once pod-{i} is scheduled on node-{i}, it will always be scheduled there in every case (e.g. restart).
3) Is above setup right way to implement such case where I need to store the data on host local directory. Or local persistent volume is better? I could not get the actual difference between the two. 4) Do I need to create local-storage storage class manually? (Above setup runs fine in docker for windows setup without creating storage class) 5) I may have other containers also which need to store the data under /home/abc directory only. So, I will be using subPath while mounting the volume in container. Do you see any issue here?
Pleas help.
hostPath volumes work well only on single-node clusters if you have a multi-node environment then you should use Local Persistent Volume
These blog posts explain the Local Persistent Volume.
Official blog - https://kubernetes.io/blog/2019/04/04/kubernetes-1.14-local-persistent-volumes-ga/
another reference - https://vocon-it.com/2018/12/20/kubernetes-local-persistent-volumes/