Persistent Volumes in Kubernetes

When you created volumes, you configured volumes within the pod definition file so every configuration information required to configure storage for the volume goes within the pod definition file.

A persistent volume is a cluster-wide pool of storage volumes configured by an administrator to be used by users deploying applications on the cluster. The users can now select storage from the pool using persistent volume claims.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-sample
spec:
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 1Gi
  hostPath:
    path: /tmp/data
$ kubectl create -f pv-sample.yaml 
persistentvolume/pv-sample created
$ kubectl get pv
NAME        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE
pv-sample   1Gi        RWO            Retain           Available                                   46s

We set apiVersion, kind, metadata, and spec.

  • accessModes defines how a volume should be mounted on the hosts whether in a ReadOnlyMany, ReadWriteOnce or ReadWriteMany mode.
  • capacity: volume capacity
  • hostPath: local directory
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-sample
spec:
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 1Gi
  awsElasticBlockStore:
    volumeID: <volume-id>
    fsType: ext4

with awsElasticBlockStore

Leave a Reply

Your email address will not be published.

ANOTE.DEV