Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cheedge Lee
Cheedge Lee

Posted on • Originally published atMedium

Kubernets Storage Demos

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
Enter fullscreen modeExit fullscreen mode

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
Enter fullscreen modeExit fullscreen mode

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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Location
    München
  • Joined

More fromCheedge Lee

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp