K8S Local 卷的使用
local
卷所代表的是某个被挂载的本地存储设备,例如磁盘、分区或者目录。即节点需要存在对应路径。local
卷只能用作静态创建的持久卷。不支持动态制备。local
卷与对应节点相绑定,如果节点绑定了某个local
卷,则这个节点会自动调度到local
卷所在节点。
下面是一个使用 local
卷和 nodeAffinity
的持久卷示例:
apiVersion: v1
kind: PersistentVolume
metadata:
name: example-pv
spec:
capacity:
storage: 100Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
# 映射到节点的本地路径,需要提前创建
path: /mnt/disks/ssd1
# 配置节点亲和性,让 local 卷绑定到某个 k8s 节点
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- example-node