目的是什么:
pvc要能实现自主调度节点,执行任务
前提:
- pvc
- pvc类型
- 哪些配置决定这个能实现调度
- 有没有不支持的类型
关键字段两个:
访问模式
pv亲和性
https://kubernetes.io/zh/docs/concepts/storage/volumes/
用这四个 CSI NFS, LOCAL, HostPath 验一下访问模式(accessModes)和 亲和性
- 先创建pv
- 创建pvc,申请pv,会根据配置的属性自动匹配pv
- 创建pod,pod能够挂卷,能够连上pvc,实现挂载
- pv有一个节点亲和性的配置可以指定哪个节点的pod可以访问它
- PV可以设置节点亲和性来限制只能通过某些Node访问Volume,可以在PV定义中的nodeAffinity字段进行设置。使用这些Volume的Pod将被调度到满足条件的Node上。
- pod可以设置volumes,pv可以设置哪些node能访问volume,就能实现符合pv要求的pod调度到可用节点上。对于Local类型的PV,需要手工设置。
- Kubernetes支持的PV类型:
NFS
:网络文件系统Local
:本地存储设备,可以通过指定块设备(Block Device)提供local PVHostPath
:宿主机目录,仅用于单机测试- Glusterfs:一种开源共享存储系统
- Cinder:OpenStack块存储系统
local
所以想干嘛!
- 新建pv,给PV带上节点亲和性
- 给pvc绑定pv,给pvc带上和pv相同的访问模式
- 创建pod,存储模式分别是nfs,local、hostpath,csi,指定pvc
- 查看pod所在节点,是不是和节点亲和性规定的相关
- 删除pod,查看pv或pvc
测试一下:
pv | 存储:nfs | 节点亲和性: | 访问模式:RWX |
---|---|---|---|
pvc | 存储类别: | 访问模式:RWX | |
pod | pvc claimName: |
pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv1
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
path: /root/data/pv1
server: 192.168.5.6
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv2
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
path: /root/data/pv2
server: 192.168.5.6
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv3
spec:
capacity:
storage: 3Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
path: /root/data/pv3
server: 192.168.5.6
pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc1
namespace: dev
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc2
namespace: dev
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc3
namespace: dev
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod1
namespace: dev
spec:
containers:
- name: busybox
image: busybox:1.30
command: ["/bin/sh","-c","while true;do echo pod1 >> /root/out.txt; sleep 10; done;"]
volumeMounts:
- name: volume
mountPath: /root/
volumes:
- name: volume
persistentVolumeClaim:
claimName: pvc1
readOnly: false
---
apiVersion: v1
kind: Pod
metadata:
name: pod2
namespace: dev
spec:
containers:
- name: busybox
image: busybox:1.30
command: ["/bin/sh","-c","while true;do echo pod2 >> /root/out.txt; sleep 10; done;"]
volumeMounts:
- name: volume
mountPath: /root/
volumes:
- name: volume
persistentVolumeClaim:
claimName: pvc2
readOnly: false
操作