I am a beginner in Kubernetes and I am learning about Persistent Volume. Currently my knowledge is that the Persistent Volume will be preserved even after the pod is deleted, but only if we delete the Persistent Volume or stop that node(in my case I only ran a single node in kubernetes cluster on my local machine). I also noticed that the files I write to that volume from my pods were not written to my disk, for reference the below is my pv.yaml file,
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv-name
namespace: my-namespace
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 25Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /home/me/dir
and this is my pvc.yaml file,
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc-name
namespace: my-namespace
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 25Gi
kindly correct me if I have any errors in the yaml specification. Now I have some doubts in it,
- How can I write to my local machines disk from the pod, how can I create a volume that will write to my disk rather than only in nodes filesystem(since the cluster was running on local machine).
- Even if(assuming my current state) it is not stored on disk, but being written on the volume mounted path, will it be removed from the RAM, since it was written to Persistence Storage
- If it was removed from RAM after being written to Persistence Storage path, how can it be not available when checking in that local filesystem directory and how can it be not available if the node is stopped or the volume is deleted.
I tried changing the storageClassName to local-storage and created a storageClass.yaml file, which is
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-storage
provisioner: kubernetes.io/no-provisioner
reclaimPolicy: Retain
volumeBindingMode: WaitForFirstConsumer
but still I couldn't see any files being written to my local machines disk
(Edited)
I am using flyte's task decorator and PodTemplate to mount my volume like,
@task(
cache=False,
requests=Resources(mem="1Gi", storage="25Gi"),
pod_template=PodTemplate(
primary_container_name="my-task",
pod_spec=V1PodSpec(
containers=[
V1Container(
name="my-task",
image="my-image",
volume_mounts=[V1VolumeMount(mount_path="/data", name="data", read_only=False)]
)
],
volumes=[
V1Volume(
name="data",
persistent_volume_claim=V1PersistentVolumeClaimVolumeSource(
claim_name="my-pvc-name",
read_only=False
)
)
],
)
),
)
How are you mounting the volume to the Pod?
It should be something like
Also, are you using Flyte?