可以使用對 pv 打 label 的方式,具體如下:
創建 pv,指定 label
$ cat nfs-pv2.yaml
apiVersion: v1
kind: PersistentVolume # PV是全局概念,不用設置namespace
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
$ 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