回顧 PV 和 PVC的週期有四個階段:
StorageClass
Storage class顧名思義,為有關儲存的類別,用來滿足PVC的動態設置,相較於靜態配置,不需事先設置PV,在建立PVC時,視Storage class屬性及PVC的需求,創造出完全符合的PV,如此一來也較有效率使用資源,Storage class有各類的policies,欄位有設置provisioner
、各類參數parameters
及回收政策reclaimPolicy
# 建立storage class
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: itHome-storage
provisioner: kubernetes.io/gce-pd
volumeBindingMode: WaitForFirstConsumer
# 建立pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: myclaim
spec:
accessModes:
- ReadWriteOnce
# 指定所屬storage class
storageClassName: itHome-storage
resources:
requests:
storage: 500Mi