To set up a Persistent Volume (PV)
and Persistent Volume Claim (PVC)
shared by pods in a KIND cluster and keep the data persisted on your laptop, you can follow these steps:
Create a directory on your laptop that will serve as the PV.
Create a YAML file for the PV and PVC, specifying the path to the directory on your laptop as the source of the PV.
Apply the YAML file to your KIND cluster to create the PV and PVC.
In your pod specification, refer to the PVC by its name to mount the volume.
Here's an example of a YAML file for the PV and PVC:
apiVersion: v1
kind: PersistentVolume
metadata:
name: mypv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /path/to/your/laptop/directory
persistentVolumeReclaimPolicy: Retain
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
To apply the YAML file, run:
kubectl apply -f pv-pvc.yaml
In your pod specification, refer to the PVC by its name to mount the volume:
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: mycontainer
image: myimage
volumeMounts:
- name: mypv
mountPath: /path/in/container
volumes:
- name: mypv
persistentVolumeClaim:
claimName: mypvc
Note: You need to adjust and test it.