gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:43:18 27 4
gpt4 key购买 nike

我有一个以这种方式运行良好的本地镜像:docker run -p 8080:8080 -v C:\Users\moritz\Downloads\1\imageService\examples1:/images -v C:\Users\moritz\entwicklung\projekte\imageCluster\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 中的容器,我看不到主机上的图像,并且在容器/logs 中包含预期文件时,我在日志挂载中看不到任何日志。

同时我也试过了(没用)

  • /host_mnt/c/...
  • /C/用户/...
  • //C/用户/...

最佳答案

如前所述here ,您可以使用下面的 hostPath 使其在 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

关于windows - Kubernetes 如何在 wsl2 支持的环境中正确挂载 Windows 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66985465/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com