Kubernetes如何在支持wsl2的环境中正确装载windows路径

Kubernetes如何在支持wsl2的环境中正确装载windows路径,windows,kubernetes,kubernetes-pod,Windows,Kubernetes,Kubernetes Pod,我有一个运行良好的本地图像: docker run-p 8080:8080-v C:\Users\moritz\Downloads\1\imageService\examples1:/images-v C:\Users\moritz\entwicklung\projekte\imagescluster\logs:/logs imageService 现在我想让它作为Kubernetes(使用Docker for Windows v1.19.7的内置)部署运行: apiVersion: apps/

我有一个运行良好的本地图像:
docker run-p 8080:8080-v C:\Users\moritz\Downloads\1\imageService\examples1:/images-v C:\Users\moritz\entwicklung\projekte\imagescluster\logs:/logs imageService

现在我想让它作为Kubernetes(使用Docker for Windows v1.19.7的内置)部署运行:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: image-service
spec:
  selector:
    matchLabels:
      app: image-service
  template:
    metadata:
      labels:
        app: image-service
    spec:
      containers:
      - name: image-service
        image: "imageservice"
        resources:
          limits:
            cpu: "0.9"
            memory: "1Gi"
        ports:
        - name: http
          containerPort: 8080
        volumeMounts:
          - mountPath: /images
            name: image-volume
          - mountPath: /logs
            name: log-volume  
      volumes:
        - name: image-volume
          hostPath:
            path: "c:\\Users\\moritz\\Downloads\\1\\imageService\\examples1"
            type: Directory
        - name: log-volume
          hostPath:
            path: /mnt/c/Users/moritz/entwicklung/projekte/imageCluster/logs
            type: Directory
如您所见,我尝试了不同的方法在windows计算机上设置主机路径,但我始终得到:

  Warning  FailedMount  0s (x4 over 4s)  kubelet            MountVolume.SetUp failed for volume "log-volume" : hostPath type check failed: /mnt/c/Users/moritz/entwicklung/projekte/imageCluster/logs is not a directory
  Warning  FailedMount  0s (x4 over 4s)  kubelet            MountVolume.SetUp failed for volume "image-volume" : hostPath type check failed: c:\Users\moritz\Downloads\1\imageService\examples1 is not a directory 
我还尝试了其他变体(两种):

  • C:\Users\moritz\entwicklung\projekte\imageCluster\logs
  • C:/Users/moritz/entwicklung/projekte/imageCluster/logs
那么如何正确设置这些windows主机路径。(下一步是将它们设置为环境变量。)

小更新:

删除
type:Directory
有助于消除错误,pod正在启动,但挂载不起作用。如果我在
/images
中“查看”容器,我看不到主机上的映像,也看不到日志装载中的任何日志,而容器/日志中包含预期的文件

同时我也试过了(没用)

  • /主机_mnt/c/
  • /C/Users/
  • //C/Users/
如前所述,您可以使用下面的主机路径使其在wsl2上工作

// C:\someDir\volumeDir
hostPath:
  path: /run/desktop/mnt/host/c/someDir/volumeDir
  type: DirectoryOrCreate
还有一个例子你可以使用

apiVersion: v1
kind: Pod
metadata:
  name: test-localpc
spec:
  containers:
  - name: test-webserver
    image: ubuntu:latest
    command: ["/bin/sh"]
    args: ["-c", "apt-get update && apt-get install curl -y && sleep 600"]
    volumeMounts:
    - mountPath: /run/desktop/mnt/host/c/aaa
      name: mydir
    - mountPath: /run/desktop/mnt/host/c/aaa/1.txt
      name: myfile
  volumes:
  - name: mydir
    hostPath:
      # Ensure the file directory is created.
      path: /run/desktop/mnt/host/c/aaa
      type: DirectoryOrCreate
  - name: myfile
    hostPath:
      path: /run/desktop/mnt/host/c/aaa/1.txt
      type: FileOrCreate

编辑我的问题-使用Docker for WindowsHey@dermoritz的内置Kubernetes,您也尝试过吗?从我所看到的,有新的评论,人们说这是为他们工作。@Jakub这是!谢谢-回答并获得分数:-)