I have an Open Source project that I deployed in Kubernetes. It has a master, data, and query pod. The data pod is used to store the data. Unfortunately, when the data pod goes down it loses all its stored data as well. So I figured, I have to use a StatefulSet with PVC. I started looking at PVC samples. Suppose I create a PV:
kind: PersistentVolume
metadata:
name: task-pv-volume1
labels:
type: local
spec:
storageClassName: local
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data1"
And then I have a Claim and a POD to bind it. This is the sample Stateful Set:
kind: StatefulSet
metadata:
name: myweb
spec:
replicas: 2
...
volumeMounts:
- name: data
mountPath: /data
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: local
resources:
requests:
storage: 100Mi
Now when I run a sample job, I realize that only one of the 2 pods is active. The other pod fails saying:
Warning FailedScheduling <unknown> 0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims.
which I believe is because I created only one PV. So I go and create a new PV,
path: "/mnt/data2"
and the pod is up and running.
In my prod setup, I want this to happen automatically. Which means I do not want to create these PVs for each replica. Is there a way to do this? Is this taken care of by Kube in some way?
Appreciate the help. If you have any further questions, please reply. I'll try my best to resolve it.