27.13.3.2. 创建 PersistentVolume
定义 PV 对象定义,如 vsphere-pv.yaml :
apiVersion: v1 kind: PersistentVolume metadata: name: pv00011 spec: capacity: storage: 2Gi2 accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Retain vsphereVolume:3 volumePath: "[datastore1] volumes/myDisk"4 fsType: ext45 重要在格式化并置备卷后更改
fsType参数的值可能会导致数据丢失和 pod 失败。创建 PV:
$ oc create -f vsphere-pv.yaml persistentvolume "pv0001" created确定创建了 PV:
$ oc get pv NAME LABELS CAPACITY ACCESSMODES STATUS CLAIM REASON AGE pv0001 <none> 2Gi RWO Available 2s
现在,您可以使用 PV 声明来请求存储,该声明现在可以使用 PV。
重要
PV 声明仅存在于用户的命名空间中,且只能被同一命名空间中的 pod 引用。尝试从不同命名空间中访问 PV 会导致 pod 失败。