我正在尝试将hostPath配置为kubernetes中的卷 . 我已经登录到VM服务器,从那里我经常使用kubernetes命令,如kubectl .
下面是pod yaml:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: helloworldanilhostpath
spec:
replicas: 1
template:
metadata:
labels:
run: helloworldanilhostpath
spec:
volumes:
- name: task-pv-storage
hostPath:
path: /home/openapianil/samplePV
type: Directory
containers:
- name: helloworldv1
image: ***/helloworldv1:v1
ports:
- containerPort: 9123
volumeMounts:
- name: task-pv-storage
mountPath: /mnt/sample
在VM服务器中,我创建了“/ home / openapianil / samplePV”文件夹,我有一个文件 . 它有一个sample.txt文件 .
一旦我尝试创建此部署 . 它不会发生错误 -
警告FailedMount 28s(x7超过59s)kubelet,aks-nodepool1-39499429-1卷的MountVolume.SetUp失败"task-pv-storage":hostPath类型检查失败:/ home / openapianil / samplePV不是目录 .
谁能帮助我理解这里的问题 .
1 回答
hostPath类型卷指的是计划运行Pod的节点(VM /机器)上的目录(在本例中为
aks-nodepool1-39499429-1
) . 因此,您至少需要在该节点上创建此目录 .要确保在该特定节点上一致地安排Pod,您需要在PodTemplate中设置spec.nodeSelector:
In most cases it's a bad idea to use this type of volume; there are some special use cases, but chance are yours is not one them!
如果由于某种原因需要本地存储,那么稍微好一点的解决方案是使用local PersistentVolumes .