介紹#
每個 StorageClass 都包含 provisioner、parameters、reclaimPolicy 這些字段會在 StorageClass 需要動態配置 PersistentVolume 以滿足 PersistentVolumeClaim (PVC) 使用到。
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: low-latency
provisioner: csi-driver.example-vendor.example
reclaimPolicy: Retain # 默认值是 Delete
allowVolumeExpansion: true
mountOptions:
- discard # 这可能会在块存储层启用 UNMAP/TRIM
volumeBindingMode: WaitForFirstConsumer
parameters:
guaranteedReadWriteLatency: "true" # 这是服务提供商特定的磁碟區插件#
每個 StorageClass 都會有 provisioner ,用來決定使用哪個磁碟區插件。(必要)
| 卷插件 | 內置製備器 | 配置範例 |
|---|---|---|
| AzureFile | ✓ | Azure File |
| CephFS | - | - |
| FC | - | - |
| FlexVolume | - | - |
| iSCSI | - | - |
| Local | - | Local |
| NFS | - | NFS |
| PortworxVolume | ✓ | Portworx Volume |
| RBD | ✓ | Ceph RBD |
| VsphereVolume | ✓ | vSphere |
回收策略#
StorageClass 動態建立的 PersistentVolume 會在 reclaimPolicy 指定回收策略,可以是 Delete 或 Retain 。預設是 Delete 。
擴展#
PersistentVolume 可以配置為可擴充,允許透過 PVC 物件來調整磁碟區大小,申請一個新的、更大的儲存容量。當 allowVolumeExpansion 定義為 true 時,下列類型的磁碟區支援擴充。
| 卷類型 | 卷擴展的Kubernetes 版本要求 |
|---|---|
| Azure File | 1.11 |
| CSI | 1.24 |
| FlexVolume | 1.13 |
| Portworx | 1.11 |
| rbd | 1.11 |
掛載選項#
由 StorageClass 動態建立的 PersistentVolume 將使用類別中 mountOptions指定的掛載選項。
如果磁碟區插件不支援掛載選項,卻指定了掛載選項,則製備操作會失敗。 掛載選項在 StorageClass 和 PV 上都不會做驗證。如果其中一個掛載選項無效,那麼這個PV 掛載作業就會失敗。





