我能够允许 pod 使用主机路径查看安装在目录中的所有硬盘驱动器。可以在主机路径“模式”中定义 PersistentVolume。我的最终解决方案是:
- 解决方案中最重要的部分:在主机路径“模式”中定义一个 PersistentVolume,并使用 nodeAffinity 确保它只会安装在具有硬盘驱动器的节点上:
apiVersion: v1
kind: PersistentVolume
metadata:
name: all-harddrives-pv
spec:
volumeMode: Filesystem
storageClassName: all-harddrives-storage
hostPath:
path: /mnt # Where all the hard drives are mounted
type: Directory
nodeAffinity: # Use nodeAffinity to ensure it will only be mounted on the node with harddrives.
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- MyNodeName
- 定义一个绑定到上述 PV 的 PersistentVolumeClaim:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: all-harddrives-pvc
spec:
storageClassName: all-harddrives-storage
- 将其安装在部署上:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 1
selector:
matchLabels:
app: my-deployment
strategy:
type: Recreate
template:
metadata:
labels:
app: my-deployment
spec:
containers:
- name: mycontainername
image: myimage
volumeMounts:
- mountPath: /mnt
name: all-harddrives-pvc
nodeSelector:
kubernetes.io/hostname: MyNodeName