0

I'm trying to mount a windows local directory to a docker container in the Kubernetes pod but have encountered errors when specifying the mounting path. I'm a newbie to Kubernetes and not sure if I'm following the correct way to mount a Windows directory.

my .yaml file looks something like this,

apiVersion: v1
kind: Pod
metadata:
  name: two-containers-local
  labels:
    name: app
spec:
  containers:
  - image: nginx
    name: nginx-container
    volumeMounts:
    - mountPath: /usr/share/nginx/html
      name: test-volume
    ports:
    - containerPort: 8080
  volumes:
  - name: test-volume
    hostPath:
      path: 'C:\test'
      type: Directory
---
apiVersion: v1
kind: Service
metadata:
  name: my-two-container-nginx-local
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 8080
    nodePort: 30002
    protocol: TCP
  selector:
    name: app 
MountVolume.SetUp failed for volume "test-volume" : hostPath type check failed: C:\test is not a directory

enter image description here

enter image description here

Yash Chauhan
  • 174
  • 13
  • That will get different content on each pod, depending on which node it runs on. You probably don't want a `hostPath:` volume here. If this is HTML content, do you want to copy it into a custom Docker image instead? – David Maze Sep 16 '22 at 10:58
  • But I want to mount a local directory from my windows to docker, how should I achieve it? – Yash Chauhan Sep 16 '22 at 11:07
  • 1
    Kubernetes is a distributed clustered container runtime environment; it's not a good match if you're trying to work with local files. Consider plain Docker and its bind-mount system, or even skipping containers entirely and working directly with code on your host system. – David Maze Sep 16 '22 at 12:51

1 Answers1

0

Can you check whether the C:/Test directory exists on the host? When the type is Directory, if the directory does not exist on the host, kubelet will not create and it will print error.

As per this GITHUB LINk add as below :

type: DirectoryOrCreate
path: /run/desktop/mnt/host/c/users/public/your_folder #give exact working mount path

As You asked how to mount a local directory from my windows to docker, follow this link might help you

Hemanth Kumar
  • 2,728
  • 1
  • 4
  • 19