d# PV
之前我们提到的Volume是定义在Pod上的,属于“计算资源”的一部分,而实际上,“网络存储”是相对独立于“计算资源”而存在的一种实体资源。比如在使用虚机的情况下,我们通常会先定义一个网络存储,然后从中划出一个“网盘”并挂接到虚机上。Persistent Volume(简称PV)和与之相关联的Persistent Volume Claim(简称PVC)也起到了类似的作用。
PV可以理解成Kubernetes集群中的某个网络存储中对应的一块存储,它与Volume很类似,但有以下区别。
- PV只能是网络存储,不属于任何Node,但可以在每个Node上访问。
- PV并不是定义在Pod上的,而是独立于Pod之外定义。
- PV目前只有几种类型:GCE Persistent Disks、NFS、RBD、iSCSCI、AWS ElasticBlockStore、GlusterFS等。
清单文件
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv001
labels:
name: pv001
spec:
accessModes: ["ReadWriteMany","ReadWriteOnce"]
capacity:
storage: 2Gi
nfs:
server: node001
path: /data/v1
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv002
labels:
name: pv002
spec:
accessModes: ["ReadWriteOnce"]
capacity:
storage: 5Gi
nfs:
server: node001
path: /data/v2
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv003
labels:
name: pv003
spec:
accessModes: ["ReadWriteMany","ReadWriteOnce"]
capacity:
storage: 20Gi
nfs:
server: node001
path: /data/v3
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv004
labels:
name: pv004
spec:
accessModes: ["ReadWriteOnce"]
capacity:
storage: 10Gi
nfs:
server: node001
path: /data/v4
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv005
labels:
name: pv005
spec:
accessModes: ["ReadWriteOnce"]
capacity:
storage: 10Gi
nfs:
server: node001
path: /data/v5
---
获取pv状态
# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv001 2Gi RWO,RWX Retain Available 6s
pv002 5Gi RWO Retain Available 45s
pv003 20Gi RWO,RWX Retain Available 45s
pv004 10Gi RWO Retain Available 45s
pv005 10Gi RWO Retain Available 45s
补充说明
pv.spec.accessModes(list)
- ReadWriteOnce:读写权限、并且只能被单个Node挂载。
- ReadOnlyMany:只读权限、允许被多个Node挂载。
- ReadWriteMany:读写权限、允许被多个Node挂载。