Description
When deployed by kubespray and the kubelet runs in in docker(kubelet_deployment_type: docker),kubelet will try to find the path setted by hostPath(a volume type when mounting a volume in pod) inside its container instead of on the host filesystem, which results in the error in kubelet, for example:”Error: lstat /opt/test: no such file or directory”
The code of kubelet(pkg/kubelet/kueblet_pods.go):
From the code we can see that when mount.SubPath is setted,kubelet will execute fileinfo, err := os.Lstat(hostPath) in code. Kubelet won’t find the path if it is running in container and with no host volume related mounted.
From the events we can see:
If subPath is not setted in yaml, kubelet with not execute fileinfo, err := os.Lstat(hostPath) and there will not be such problem.
Related Issues
https://github.com/kubernetes-incubator/kubespray/issues/1715
https://github.com/kubernetes/kubernetes/issues/56339