我们可以使用对 pv 打 label 的方式,具体如下:
创建 pv,指定 label
-[appuser@chenqiang-dev pvtest]$ cat nfs-pv2.yaml apiVersion: v1 kind: PersistentVolume metadata: name: nfs-pv2 namespace: chenqiang-pv-test labels: pv: nfs-pv2 spec: capacity: storage: 100Mi accessModes: - ReadWriteMany nfs: # FIXME: use the right IP server: 10.130.44.20 path: "/test/mysql-nfs01"
然后创建 pvc,使用 matchLabel 来关联刚创建的 pv:nfs-pv2
-[appuser@chenqiang-dev pvtest]$ cat nfs-pvc2.yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: nfs-pvc2 namespace: chenqiang-pv-test spec: accessModes: - ReadWriteMany storageClassName: "" resources: requests: storage: 90Mi selector: matchLabels: pv: nfs-pv2