首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >minikube + hostPath

minikube + hostPath
EN

Stack Overflow用户
提问于 2021-09-27 08:22:20
回答 1查看 1K关注 0票数 2

我不顾一切地试图应用一个简单的pod规范,而没有任何运气,即使有了以前的答案:Mount local directory into pod in minikube

yaml文件:

代码语言:javascript
运行
复制
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个文件

代码语言:javascript
运行
复制
ls /tmp/data/
file2.txt file3.txt hello

然而,当我做kubectl describe pods时,这就是我得到的

代码语言:javascript
运行
复制
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时的输出:

代码语言:javascript
运行
复制
  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起到了帮助作用。但是我仍然没有看到/data/里面的任何东西,
  • 也从/tmp/变成了minikube中的另一个文件夹。与MacOs有关.
EN

Stack Overflow用户

发布于 2021-10-04 14:42:49

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

从/tmp/转换到另一个文件夹的

在minikube中起到了帮助作用。因为某种原因,minikube不喜欢/tmp/,所以与MacOs有关

对此问题的解释:您不能将/tmp挂载到/tmp。问题不在于macOS,而在于您的方式。我试着用几种方法重现这个问题。我用了一个码头,得到了一个非常有趣的错误:

代码语言:javascript
运行
复制
docker: Error response from daemon: Duplicate mount point: /tmp.

这个错误清楚地说明了问题的所在。如果您将目录挂载到其他地方,则所有内容都应该正常工作(这已得到确认):

我是否正确地理解,当您将挂载点更改为另一个文件夹时,它是否有效?这是正确的。由于某种原因,minikube不喜欢/tmp/

我知道在我的例子中,您使用的是hyperkit而不是docker,但是唯一的区别将是您在屏幕上得到的消息。就码头工人而言,这是非常清楚的。

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69343347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档