首页 > 解决方案 > Hostpath 卷未安装在 Windows 的 Docker-desktop 上运行的 kubernetes 上

问题描述

我在 Docker-desktop for windows 上运行 kubernetes。我正在从我的 WSL 连接到集群。我所有的 pod 都运行正常。我正在尝试使用主机路径在我的 jupyterlab(pod)上安装一个卷。下面是我的配置

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jupyter
  labels:
    app: jupyter
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jupyter
  template:
    metadata:
      labels:
        app: jupyter
    spec:
      containers:
      - name: jupyter
        image: jupyter:1.1
        ports:
        - containerPort: 8888
        securityContext:
          runAsNonRoot: true
          runAsUser: 1000
        volumeMounts:
          - name: mydir
            mountPath: /notebooks
      volumes:
        - name: mydir
          hostPath:
            # directory location on host
            path: /home/<myuser>/data
            # this field is optional
            type: DirectoryOrCreate

吊舱启动没有任何问题。但我没有看到我保存在我的主机路径中的笔记本到我的 jupyter 实验室,反之亦然(如果我在 jupyter 实验室保存笔记本,它不会保存到我的主机路径)。

我按照https://kubernetes.io/docs/concepts/storage/volumes/#hostpath上的教程进行操作

我想指出我正在使用 @FROM jupyter/datascience-notebook:python-3.7.6" 作为我的 docker 映像。

我尝试安装 /home/jovyan/ 但它在启动 pod 时给了我访问相关的错误。所以我恢复到“/notebooks”

标签: dockerkubernetesjupyter-notebookkubernetes-pod

解决方案


在 Windows 上编写路径的方式似乎存在问题,我在下面的参考资料中看到了该问题。

解决方案:

  • 如果您的文件位于 C: 驱动器中,则应将其转换为以下内容
/host_mnt/c/path/to/my/folder
  • 如果上述方法不起作用,您可能需要删除“类型:DirectoryOrCreate”并重试。

参考资料: https ://github.com/kubernetes/kubernetes/issues/59876#issuecomment-628955935 https://github.com/docker/for-win/issues/1703#issuecomment-366701358


推荐阅读