【问题标题】:minikube + hostPathminikube + 主机路径
【发布时间】:2021-11-19 09:51:18
【问题描述】:

我拼命尝试应用一个简单的 pod 规范,但没有任何运气,即使有这个先前的答案:Mount local directory into pod in minikube

yaml 文件:

apiVersion: v1
kind: Pod
metadata:
  name: hostpath-pod
spec:
  containers:
    - image: httpd
      name: hostpath-pod
      volumeMounts:
        - mountPath: /data
          name: test-volume
  volumes:
    - name: test-volume
      hostPath:
        # directory location on host
        path: /tmp/data/

我用:minikube start --mount-string="/tmp:/tmp" --mount 启动了 minikube 集群,/tmp/data 中有 3 个文件:

ls /tmp/data/
file2.txt file3.txt hello

但是,这就是我在kubectl describe pods 时得到的结果:

Events:
  Type     Reason     Age                  From               Message
  ----     ------     ----                 ----               -------
  Normal   Scheduled  2m26s                default-scheduler  Successfully assigned default/hostpath-pod to minikube
  Normal   Pulled     113s                 kubelet, minikube  Successfully pulled image "httpd" in 32.404370125s
  Normal   Pulled     108s                 kubelet, minikube  Successfully pulled image "httpd" in 3.99427232s
  Normal   Pulled     85s                  kubelet, minikube  Successfully pulled image "httpd" in 3.906807762s
  Normal   Pulling    58s (x4 over 2m25s)  kubelet, minikube  Pulling image "httpd"
  Normal   Created    54s (x4 over 112s)   kubelet, minikube  Created container hostpath-pod
  Normal   Pulled     54s                  kubelet, minikube  Successfully pulled image "httpd" in 4.364295872s
  Warning  Failed     53s (x4 over 112s)   kubelet, minikube  Error: failed to start container "hostpath-pod": Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting "/tmp/data" to rootfs at "/data" caused: stat /tmp/data: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
  Warning  BackOff    14s (x6 over 103s)   kubelet, minikube  Back-off restarting failed container

不知道我在这里做错了什么。如果有帮助,我正在使用 minikube 版本 v1.23.2,这是我启动 minikube 时的输出:

????  minikube v1.23.2 on Darwin 11.5.2
    ▪ KUBECONFIG=/Users/sachinthaka/.kube/config-ds-dev:/Users/sachinthaka/.kube/config-ds-prod:/Users/sachinthaka/.kube/config-ds-dev-cn:/Users/sachinthaka/.kube/config-ds-prod-cn
✨  Using the hyperkit driver based on existing profile
????  Starting control plane node minikube in cluster minikube
????  Restarting existing hyperkit VM for "minikube" ...
❗  This VM is having trouble accessing https://k8s.gcr.io
????  To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
????  Preparing Kubernetes v1.22.2 on Docker 20.10.8 ...
????  Verifying Kubernetes components...
????  Creating mount /tmp:/tmp ...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
????  Enabled addons: storage-provisioner, default-storageclass

❗  /usr/local/bin/kubectl is version 1.18.0, which may have incompatibilites with Kubernetes 1.22.2.
    ▪ Want kubectl v1.22.2? Try 'minikube kubectl -- get pods -A'
????  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

有什么我可以尝试的吗? :'(

更新 1

  • minikube 更改为microk8s 有帮助。但我仍然没有在 pod 中看到 /data/ 内部的任何内容。
  • 还从/tmp/ 更改为其他文件夹有助于minikube。与 MacOs 有关。

【问题讨论】:

  • 您是否尝试从path: /tmp/data/ 中删除/?试试path: /tmp/data。另请查找文档:kubernetes.io/docs/concepts/storage/volumes/#hostpath
  • 见上面的更新。
  • @sachinruk,我理解正确吗,当您将挂载点更改为不同的文件夹时,它可以工作吗?
  • @MikołajGłodziak 这是正确的。出于某种原因 minikube 不喜欢 /tmp/

标签: kubernetes kubectl minikube


【解决方案1】:

OP 说,这个问题已经解决了:

从 /tmp/ 更改为其他文件夹有助于 minikube。与MacOs有关 由于某种原因 minikube 不喜欢 /tmp/

对这个问题的解释: 您不能将/tmp 挂载到/tmp。问题不在于 macOS,而在于您的操作方式。我试图以多种方式重现这个问题。我使用了一个 docker,得到了一个非常有趣的错误:

docker: Error response from daemon: Duplicate mount point: /tmp.

这个错误清楚地表明了问题所在。如果您将目录安装在其他地方,一切都应该正常(已确认):

我是否理解正确,当您将挂载点更改为不同的文件夹时,它是否有效?

这是正确的。由于某种原因 minikube 不喜欢 /tmp/

我知道在我的情况下您使用的是 hyperkit 而不是 docker,但唯一的区别在于您在屏幕上看到的消息。 docker的情况下就很清楚了。

【讨论】:

    猜你喜欢
    • 2019-06-22
    • 2017-05-19
    • 2021-05-27
    • 2015-11-06
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 2020-10-27
    • 1970-01-01
    相关资源
    最近更新 更多