繁体   English   中英

docker for windows 上的 Kubernetes,带有 hostPath 的持久卷不允许操作

[英]Kubernetes on docker for windows, persistent volume with hostPath gives Operation not permitted

我正在尝试将 Windows 中的文件夹连接到容器文件夹。 这适用于需要读取文件夹中文件的 .NET 应用程序。 在普通的 docker 容器中,使用 docker-compose,应用程序可以正常运行,但由于这只是我们必须监控的几个不同应用程序之一,因此我们正试图让 kubernetes 参与其中。 这也是我们失败的地方。 作为 kubernetes 的初学者,我使用 kompose.exe 将 compose 文件转换为 kuberetes 样式。 但是,无论我使用 hostPath 还是 persistentVolumeClaim 作为标志,我都无法“开箱即用”地工作。 使用 hostPath 时,路径非常不正确,而使用 persistentVolumeClaim 时,我收到一条警告,指出不支持主机上的卷挂载。 因此,我尝试自己完成该部分,但既不能使用持久卷,也不能直接在部署文件中输入挂载数据。 我最接近的是我可以进入文件夹,并且可以更改到其中的子文件夹,但是一旦我尝试运行任何其他命令,无论是“ls”还是“cat”,我都会收到“不允许操作” . 这是我的 docker compose 文件,它按预期工作

version: "3.8"
services:
    test-create-hw-file:
        container_name: "testcreatehwfile"
        image: test-create-hw-file:trygg
        network_mode: "host"
        volumes:
            - /c/temp/testfiles:/app/files

在该文件上运行 konvert compose:

PS C:\temp> .\kompose.exe convert -f .\docker-compose-tchwf.yml --volumes hostPath -v
DEBU Checking validation of provider: kubernetes
DEBU Checking validation of controller:
DEBU Docker Compose version: 3.8
WARN Service "test-create-hw-file" won't be created because 'ports' is not specified
DEBU Compose file dir: C:\temp
DEBU Target Dir: .
INFO Kubernetes file "test-create-hw-file-deployment.yaml" created
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: C:\temp\kompose.exe convert -f .\docker-compose-tchwf.yml --volumes hostPath -v
    kompose.version: 1.26.1 (a9d05d509)
  creationTimestamp: null
  labels:
    io.kompose.service: test-create-hw-file
  name: test-create-hw-file
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: test-create-hw-file
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        kompose.cmd: C:\temp\kompose.exe convert -f .\docker-compose-tchwf.yml --volumes hostPath -v
        kompose.version: 1.26.1 (a9d05d509)
      creationTimestamp: null
      labels:
        io.kompose.service: test-create-hw-file
    spec:
      containers:
        - image: test-create-hw-file:trygg
          name: testcreatehwfile
          resources: {}
          volumeMounts:
            - mountPath: /app/files
              name: test-create-hw-file-hostpath0
      restartPolicy: Always
      volumes:
        - hostPath:
            path: C:\temp\c\temp\testfiles
          name: test-create-hw-file-hostpath0
status: {}

在该文件上运行 kubectl apply 只会给出臭名昭著的错误“错误:来自守护进程的错误响应:无效模式:/app/files”,这意味着,据我所知,并不是“/app/files”是错误的,但假定连接的文件夹的格式不正确。 这是相当奇怪的C:\temp\c\temp\testfiles行。 在谷歌搜索和大量阅读之后,我有两种方法可以将其更改为/c/temp/testfiles/host_mnt/c/temp/testfiles 两者都以相同的“不允许操作”结束。 我正在通过进入 docker 桌面中容器上的 CLI 来检查这一点。

测试中的图像只是一个应用程序,现在除了等待五分钟不退出,然后我可以检查文件夹之外什么都不做。 我以 root 身份登录到 shell,并且在执行 'ls -lA' 时我有该文件夹的这一行:

drwxrwxrwx 1 root root      0 Feb  7 12:04 files

此外, docker-user拥有对c:\temp\testfiles文件夹的完全访问权限。

一些版本数据:

Docker version 20.10.12, build e91ed57

Kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.5", GitCommit:"5c99e2ac2ff9a3c549d9ca665e7bc05a3e18f07e", GitTreeState:"clean", BuildDate:"2021-12-16T08:38:33Z", GoVersion:"go1.16.12", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.5", GitCommit:"5c99e2ac2ff9a3c549d9ca665e7bc05a3e18f07e", GitTreeState:"clean", BuildDate:"2021-12-16T08:32:32Z", GoVersion:"go1.16.12", Compiler:"gc", Platform:"linux/amd64"}

Kompose version
1.26.1 (a9d05d509)

Host OS: Windows 10, 21H2

//试一下

很高兴我最初的评论解决了您的问题。 我想以官方答案的形式稍微扩展一下我的想法。

要在 Docker Desktop for Windows 上使用 Kubernetes 挂载卷,路径将是:

/run/desktop/mnt/host/c/PATH/TO/FILE

不幸的是,没有官方文档,但这里有一个很好的评论,说明这与 Docker 守护进程有关:

/mnt/wsl 实际上是跨发行版挂载 tmpfs 的挂载点
Docker Daemon 将其挂载在其 /run/desktop/mnt/host/wsl 目录中

多亏了 RadkW,问题现在得到了解决。 路径应该写成/run/desktop/mnt/host/c/PATH/TO/FILE ,在我的例子中: /run/desktop/mnt/host/c/temp/testfiles 如果我找到任何有关此的文档,我将添加一个来源。

我面临同样的问题,花了3天时间。 最后我通过重新配置解决了如下:

type: DirectoryOrCreate
path: /run/desktop/mnt/host/c/users/public/your_folder

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM