Creating Persistent Volumes in Minikube cluster
This section describes the steps to create a PVC for storing JDBC drivers.
- Create a Persistent Volume. This allocates storage within the cluster. For example:
apiVersion: v1 kind: PersistentVolume metadata: name: local-pv spec: capacity: storage: 100Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Retain storageClassName: local-storage local: path: /home/docker # Update this path based on your cluster, e.g., /var/mnt nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - minikube
Run the following command to apply the configuration:
kubectl apply -f pv.yaml
- Create a Persistent Volume Claim (PVC). This requests storage from the PV. For
example:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: local-pvc spec: accessModes: - ReadWriteMany resources: requests: storage: 100Gi storageClassName: local-storage
Run the following command to apply the PVC:
kubectl apply -f pvc.yaml
- Create a Pod to copy files from the local system to the PV:
apiVersion: v1 kind: Pod metadata: name: file-copy-pod labels: name: file-copy-pod spec: containers: - name: file-copy-container image: busybox command: - "sh" - "-c" - "thmod -R 755 /data && sleep 3000" # Keep pod running until file operation completes volumeMounts: - name: local-storage mountPath: /data securityContext: runAsUser: 0 # Run as root user resources: limits: memory: "128Mi" cpu: "500m" volumes: - name: local-storage persistentVolumeClaim: claimName: local-pvc restartPolicy: Never
- Copy files to the Pod using the following
command:
kubectl cp a.pdf file-copy-pod:/data/
Replace
a.pdf
with a file or folder you wish to transfer. The destination inside the Pod is/data
, which corresponds to the path defined involumeMounts
.