k8s 如何关联pvc到特定的pv

可以使用对 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
posted @ 2021-04-23 18:04  哈喽哈喽111111  阅读(1052)  评论(0编辑  收藏  举报