hostPath作为kubernetes中的卷 [英] hostPath as volume in kubernetes
问题描述
我正在尝试将hostPath配置为kubernetes中的卷.我已经登录到VM服务器,通常从那里使用kubernetes命令,例如kubectl.
I am trying to configure hostPath as the volume in kubernetes. I have logged into VM server, from where I usually use kubernetes commands such as kubectl.
下面是豆荚的豆浆:
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文件.
In VM server, I have created "/home/openapianil/samplePV" folder and I have a file present in it. It has a sample.txt file.
一旦我尝试创建此部署.它不会发生错误-
警告FailedMount 28s(x7超过59s)kubelet,aks-nodepool1-39499429-1 MountVolume.SetUp失败,卷"task-pv-storage":hostPath类型检查失败:/home/openapianil/samplePV不是目录.
once I try to create this deployment. it does not happen with error -
Warning FailedMount 28s (x7 over 59s) kubelet, aks-nodepool1-39499429-1 MountVolume.SetUp failed for volume "task-pv-storage" : hostPath type check failed: /home/openapianil/samplePV is not a directory.
任何人都可以在这里帮助我理解问题.
Can anyone please help me in understanding the problem here.
推荐答案
hostPath
类型的卷是指计划运行Pod的节点(VM/计算机)上的目录(在本例中为aks-nodepool1-39499429-1
).因此,您至少需要在该节点上创建此目录.
hostPath
type volumes refer to directories on the Node (VM/machine) where your Pod is scheduled for running (aks-nodepool1-39499429-1
in this case). So you'd need to create this directory at least on that Node.
To make sure your Pod is consistently scheduled on that specific Node you need to set spec.nodeSelector
in the PodTemplate:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: helloworldanilhostpath
spec:
replicas: 1
template:
metadata:
labels:
run: helloworldanilhostpath
spec:
nodeSelector:
kubernetes.io/hostname: aks-nodepool1-39499429-1
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
在大多数情况下,使用这种类型的卷是个坏主意;有一些特殊的用例,但您可能不是其中的一个!
如果出于某种原因需要本地存储,则更好的解决方案是使用 local
持久卷.
If you need local storage for some reason then a slightly better solution is to use local
PersistentVolumes.
这篇关于hostPath作为kubernetes中的卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!