持久存储卷 (PV)

持久存储卷 (PV, Persistent Volume)

PV 配置文件

persistent-volume.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: test-pv
  labels:
    type: nfs #指定类型是NFS
spec:
  capacity: #指定访问空间是15G
    storage: 15Gi
  accessModes: #指定访问模式是能在多节点上挂载,并且访问权限是读写执行
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle #指定回收模式是自动回收,当空间被释放时,K8S自动清理,然后可以继续绑定使用
  nfs:
    server: 172.18.50.200
    path: /test

Reclaim 回收策略

  • Retain – 允许用户手动回收
  • Recycle – 删除 PV 上的数据 (“rm -rf /thevolume/*”)
  • Delete – 删除 PV

创建 PV

kubectl create -f persistent-volume.yaml

状态已经变成可用

获取 pv 信息

pv 没有命名空间的限制

$ kubectl get pv
NAME      CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM           STORAGECLASS   REASON   AGE
test-pv   15Gi       RWX            Recycle          Bound    test/nfs-data                           51s

查看 pv 详情

$ kubectl describe pv test-pv
Name:            test-pv
Labels:          type=nfs
Annotations:     pv.kubernetes.io/bound-by-controller: yes
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:
Status:          Bound
Claim:           test/nfs-data
Reclaim Policy:  Recycle
Access Modes:    RWX
VolumeMode:      Filesystem
Capacity:        15Gi
Node Affinity:   <none>
Message:
Source:
    Type:      NFS (an NFS mount that lasts the lifetime of a pod)
    Server:    192.168.126.130
    Path:      /test
    ReadOnly:  false
Events:        <none>

可以看到, test-pv 被 PVC test/nfs-data 声明, 挂载到 192.168.126.130/test

MIT Licensed | Copyright © 2018-present 滇ICP备16006294号

Design by Quanzaiyu | Power by VuePress