In myprevious post, shows the basic concepts for Storage in kubernetes, here I want to use some simplified demos to show how these concepts exactly used in a cluster.
Here we use one Emphemral volume -- HostPath type, and a Persistent Volume -- local type as two examples:
HostPath Type
HostPath Type is an empheral volume, even if it will keep the stored file after Pod deleted.
Main Difference:
- No PVC, directly bound with Pod
- Manually create affinity for Pod
apiVersion:v1kind:PersistentVolumemetadata:name:hostpath-pvspec:capacity:storage:100MiaccessModes:-ReadWriteOncehostPath:path:/mnt/data# if not exist will create---apiVersion:v1kind:Podmetadata:name:pod-using-hostpathspec:affinity:nodeAffinity:# host path should have the nodeAffinity itemrequiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:-matchExpressions:-key:kubernetes.io/hostnameoperator:Invalues:-node01volumes:-name:hostpath-volumehostPath:path:/mnt/datacontainers:-name:appimage:busyboxcommand:["sleep","3600"]volumeMounts:-mountPath:/dataname:hostpath-volume
Local Type
local type is Persistent Volume type, therefore we need create a PVC, and also with a StorageClass.
Main Difference:
- PVC
- SC
- PV need nodeAffinity
- Pod will be assigned according to the node of PV automatically
apiVersion:v1kind:PersistentVolumemetadata:name:local-pvspec:capacity:storage:100MiaccessModes:-ReadWriteOncestorageClassName:local-storage# just a templatelocal:path:/mnt/data# this should existnodeAffinity:required:nodeSelectorTerms:-matchExpressions:-key:kubernetes.io/hostnameoperator:Invalues:-node01---apiVersion:v1kind:PersistentVolumeClaimmetadata:name:local-pvcspec:storageClassName:local-storageaccessModes:-ReadWriteOnceresources:requests:storage:50Mi---apiVersion:v1kind:Podmetadata:name:pod-using-localspec:volumes:-name:local-volumepersistentVolumeClaim:claimName:local-pvccontainers:-name:appimage:busyboxcommand:["sleep","3600"]volumeMounts:-mountPath:/dataname:local-volume
Reuse the PV
If we have delete the PV, but still want to continue using the content stored, we need to specify theclaimRef
field and make sure thepersistentVolumeReclaimPolicy
field isRetain
(forlocal type
the official documnetDON'T recommend setpersistentVolumeReclaimPolicy: Delete
.
for more details of reuse the PV, pls check the official documents:here.
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse