Currently i try to implement PersistentVolume in my yaml file . I read a lot of documentation on internet and i dont understand why when i go to the dashboard pod i've this message
persistentvolumeclaim "karaf-conf" not found
pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: karafpod
spec:
containers:
- name: karaf
image: xxx/karaf:ids-1.1.0
volumeMounts:
- name: karaf-conf-storage
mountPath: "/apps/karaf/etc"
volumes:
- name: karaf-conf-storage
persistentVolumeClaim:
claimName: karaf-conf-claim
PersistentVolumeClaimKaraf.yml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: karaf-conf-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Mi
PersistentVolume.yaml
kind: PersistentVolume
apiVersion: v1
metadata:
name: karaf-conf
labels:
type: local
spec:
capacity:
storage: 100Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/apps/karaf/etc"
You will find below the result of the command kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
karaf-conf 100Mi RWO Retain Terminating default/karaf-conf-claim 17h
karaf-conf-persistentvolume 100Mi RWO Retain Released default/karaf-conf 1h
kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
karaf-conf-claim Terminating karaf-conf 10Mi RWO manual 17h
A PersistentVolumeClaim (PVC) is a request for storage by a user. It is similar to a Pod. Pods consume node resources and PVCs consume PV resources. Pods can request specific levels of resources (CPU and Memory).
A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by server/storage/cluster administrator or dynamically provisioned using Storage Classes. It is a resource in the cluster just like node. A PersistentVolumeClaim (PVC) is a request for storage by a user which can be attained from PV.
With hostPath, you don't need PersistentVolume or PersistentVolumeClaim objects, so this might be easier depending on your need:
# file: pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: karafpod
spec:
containers:
- name: karaf
image: xxx/karaf:ids-1.1.0
volumeMounts:
- name: karaf-conf-storage
mountPath: "/apps/karaf/etc" # Path mounted in container
# Use hostPath here
volumes:
- name: karaf-conf-storage
hostPath:
path: "/apps/karaf/etc" # Path from the host
Then delete the other two .yaml files PersistentVolumeClaimKaraf.yml
and PersistentVolume.yml
For official documentation, see: https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
Edit: Noticed that spec.containers.VolumeMounts.mountPath and spec.containers.volumes.hostPath.path from the original post were the same, so added comments in yaml to clarify purpose of each.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With