主机路径作为kubernetes中的卷
我正在尝试将hostPath配置为kubernetes中的卷。我已经登录到VM服务器,在那里我通常使用kubernetes命令,比如kubectl 以下是pod yaml:主机路径作为kubernetes中的卷,kubernetes,Kubernetes,我正在尝试将hostPath配置为kubernetes中的卷。我已经登录到VM服务器,在那里我通常使用kubernetes命令,比如kubectl 以下是pod yaml: apiVersion: apps/v1beta1 kind: Deployment metadata: name: helloworldanilhostpath spec: replicas: 1 template: metadata: labels: run: hellowo
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文件
一旦我尝试创建此部署。不会发生错误-警告失败装载28s(x7/59s)kubelet,aks-nodepool1-39499429-1装载卷。卷“任务pv存储”的安装失败:主机路径类型检查失败:/home/openapanil/samplePV不是目录 任何人都可以帮助我理解这里的问题。类型卷指计划运行Pod的节点(VM/计算机)上的目录(
aks-nodepool1-39499429-1,在本例中为)。因此,您需要至少在该节点上创建此目录
要确保Pod在该特定节点上的调度一致,需要在Pod模板中设置:
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
在大多数情况下,使用这种音量是个坏主意;有一些特殊的用例,但机会是你的,不是其中之一强>
如果出于某种原因需要本地存储,那么更好的解决方案是使用PersistentVolumes