Storage Class Name
β Is storageClassName mandatory in a PersistentVolume (PV)?¶
πΉ No, it's not mandatory β but it depends on the use case:
β When to include it:¶
You should include storageClassName in the PV if you're manually matching it to a PVC that also specifies one. This ensures binding happens correctly.
Example: If your PVC says storageClassName: gold, your PV must have storageClassName: gold.
β When to avoid or leave it empty:¶
If you're only using static provisioning and want the PV to be bound to a PVC without any storage class, you can leave it out or set it explicitly to an empty string ("").
storageClassName: "" # This disables dynamic provisioning for this PV
π Static vs Dynamic Provisioning and storageClassName¶
| Provisioning Type | Who creates the PV? | Does PV need storageClassName? | Notes |
|---|---|---|---|
| Static Provisioning | Admin/User manually writes PV | β Recommended | Must match PVC's storageClassName |
| Dynamic Provisioning | Kubernetes auto-creates PV from StorageClass | β Not needed in PV (it's auto-filled) | PVC must have storageClassName |
| No Provisioning / Manual Binding | You want to match PVC with no storage class | storageClassName: "" in PV and PVC | Prevents dynamic provisioning |
π·οΈ What are different storageClassName values?¶
These names are arbitrary labels that are defined in your StorageClass objects. Common examples include:
storageClassName | Description |
|---|---|
| standard | Default for many clusters (GKE, Minikube, etc.) |
| gp2, gp3 | AWS EBS volume types |
| premium | Azure premium storage |
| nfs-sc | NFS-backed dynamic provisioning |
| rook-ceph-block | Ceph-based CSI volume plugin |
| longhorn | Lightweight distributed block storage |
| manual | Custom name for manually provisioned PVs |
Note: When you say storageClassName: gp2 in your PVC, Kubernetes looks for a StorageClass with metadata.name: gp2.
π How It Affects PV Manifests¶
πΉ Static Provisioning PV Example¶
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-static
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
storageClassName: manual # Manually defined name to match PVC
hostPath:
path: "/mnt/data"
β
This works only when PVC requests storageClassName: manual.
πΉ Dynamic Provisioning PV Example¶
You do not write PVs manually β the StorageClass handles that. Example:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: ebs-gp2
provisioner: kubernetes.io/aws-ebs
parameters:
type: gp2
Then PVC:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-ebs
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: ebs-gp2
π¦ A matching PV is created automatically, and storageClassName in PV is filled behind the scenes.
π‘ Pro Tips¶
β If storageClassName is missing from the PVC, it uses the default StorageClass (unless you explicitly set it to "").
β
Always make sure storageClassName in your PV β PVC β StorageClass are aligned for successful binding.
π storageClassName Explanation¶
The value of storageClassName is not fixed; it can be any name, but it must match the name of the StorageClass or the value in the PV and PVC manifest for proper binding.
Explanation:¶
storageClassName in PV:¶
- The
storageClassNamein the PersistentVolume (PV) manifest defines whichStorageClassthis PV is associated with. - The
storageClassNamein PV should match aStorageClass(or be left empty for default dynamic provisioning). - If you're manually provisioning, the
storageClassNamemust match the name of a pre-existingStorageClass.
storageClassName in PVC:¶
- The
storageClassNamein the PersistentVolumeClaim (PVC) manifest should match theStorageClassyou want to request. - If you specify one, Kubernetes will try to bind this PVC to a PV with the same
storageClassName. - If a matching
StorageClassexists, and thereβs an available PV with the samestorageClassName, it will bind the PVC to that PV.
storageClassName in StorageClass:¶
- This is the actual name of the
StorageClass. When you create aStorageClass, you define astorageClassNamethat you will later refer to in your PV and PVC.
Summary:¶
storageClassNamecan be any name as long as it matches between the PV, PVC, andStorageClasswhere necessary.- In static provisioning, you manually create the PV and make sure the
storageClassNamematches theStorageClassyou're working with. - In dynamic provisioning, you create a PVC with a
storageClassNamematching an existingStorageClass, and Kubernetes will automatically create a PV based on thatStorageClass.
Direct Answer:¶
Yes, the value of storageClassName is not fixed, but it must match between PV, PVC, and the StorageClass for the correct binding and provisioning.