Vasu Youth
Vasu Youth

Reputation: 373

Need of storageClassName in PV and PVC

I created PV as follows:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: foo-pv
spec:
  storageClassName: "my-storage"
  claimRef:
    name: foo-pvc
    namespace: foo

Why we need to give storageClassName in PV? When Storage class creates PV, why to give storageClassName in PV?

Can someone help me to understand this?

Upvotes: 6

Views: 6200

Answers (2)

jhook
jhook

Reputation: 181

You can have 2 types of PVs:

  1. dynamic provisioned by StorageClasses
  2. manually/static created by admins

Dynamically -> this is often used within cloud, for instance when you want to mount an Azure blob/file to a pod. In this case you don't have control over PV name, StorageClass create and bound random created PVs.

enter image description here

Manually -> this will give more control, you can assign a specific name to PV, a specific StorageClass that has Retain policy (do not delete PV after Released by Pod). In result is much easier to reuse that PV, knowing it name and StorageClass membership.

enter image description here

Upvotes: 2

According to Kubernetes Official documentation:

Why we need to give storageClassName in PV?

Each StorageClass contains the fields provisioner, parameters, and reclaimPolicy, which are used when a PersistentVolume belonging to the class needs to be dynamically provisioned.

The name of a StorageClass object is significant, and is how users can request a particular class. Administrators set the name and other parameters of a class when first creating StorageClass objects, and the objects cannot be updated once they are created.

When Storage class creates PV, why to give storageClassName in PV?

A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes. It is a resource in the cluster just like a node is a cluster resource.

Cluster administrators need to be able to offer a variety of PersistentVolumes that differ in more ways than size and access modes, without exposing users to the details of how those volumes are implemented. For these needs, there is the StorageClass resource.

If you wish to know more about Storage class resources, please follow this link, or this one to know more about Persistent Volumes.

Upvotes: 1

Related Questions