//NFS使用PV和PVC
1、配置nfs存储
2、定义PV
实现 下图的pv和pvc测试
pv的定义
这里定义5个PV,并且定义挂载的路径以及访问模式,还有PV划分的大小
vim /pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv001
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
- ReadWriteMany
#persistentVolumeReclaimPolicy: Recycle
#storageClassName: slow
nfs:
path: /opt/k8s/v1
server: 192.168.47.60
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv002
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
#persistentVolumeReclaimPolicy: Recycle
#storageClassName: slow
nfs:
path: /opt/k8s/v2
server: 192.168.47.60
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv003
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
- ReadWriteMany
#persistentVolumeReclaimPolicy: Recycle
#storageClassName: slow
nfs:
path: /opt/k8s/v3
server: 192.168.47.60
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv004
spec:
capacity:
storage: 4Gi
accessModes:
- ReadWriteOnce
- ReadWriteMany
#persistentVolumeReclaimPolicy: Recycle
#storageClassName: slow
nfs:
path: /opt/k8s/v4
server: 192.168.47.60
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv005
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
- ReadWriteMany
#persistentVolumeReclaimPolicy: Recycle
#storageClassName: slow
nfs:
path: /opt/k8s/v5
server: 192.168.47.60
---
创建使用静态pv
定义PVC
这里定义了pvc的访问模式为多路读写,该访问模式必须在前面pv定义的访问模式之中。定义PVC申请的大小为2Gi,此时PVC会自动去匹配多路读写且大小为2Gi的PV,匹配成功获取PVC的状态即为Bound
测试访问
在存储服务器上创建index.html,并写入数据,通过访问Pod进行查看,可以获取到相应的页面
实现 NFS 的动态 PV 创建
配置nfs存储
创建存储卷插件的pod
创建 StorageClass,负责建立 PVC 并调用 NFS provisioner 进行预定的工作,并让 PV 与 PVC 建立关联