加了type: Directory后建立pod失败
来源:10-3 HostPath编排讲解

404_
2023-05-10
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 4m59s default-scheduler Successfully assigned test/alpine to 192.168.2.58
Warning FailedMount 50s (x10 over 5m) kubelet MountVolume.SetUp failed for volume "workdir" : hostPath type check failed: /workdir is not a directory
Warning FailedMount 42s (x2 over 2m57s) kubelet Unable to attach or mount volumes: unmounted volumes=[workdir], unattached volumes=[workdir kube-api-access-j6ss7]: timed out waiting for the condition
我发现在我的测试中,如果加了hostPath.type: Directory,就会报如上的错误,我也百度了一下,说把type: Directory去掉就行了。
如下是我的yaml文件
apiVersion: v1
kind: Pod
metadata:
name: alpine
namespace: test
spec:
initContainers:
- name: download
image: harbor.magedu.net/baseimages/alpine
command: [ "/bin/sh","-c" ]
args: [ "wget http://www.baidu.com -O /workdir/index.html" ]
volumeMounts:
- name: workdir
mountPath: /workdir
containers:
- name: web
image: harbor.magedu.net/pub-images/nginx-base:v1.18.0
ports:
- containerPort: 80
hostPort: 8080
volumeMounts:
- name: workdir
mountPath: /usr/share/nginx/html
volumes:
- name: workdir
hostPath:
# type: Directory
path: /workdir
写回答
1回答
-
暮闲
2023-05-12
同学你好 不是添加Directory类型错误哦 而是Diretory这种HostPath卷类型决定的,这个要求宿主机必须要有这个目录才行,而DirectoryOrCreate则是没有改目录会创建,所以不会报错。
10
相似问题