1

I am unable to upload a file through a deployment YAML in Kubernetes.
The deployment YAML

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  labels:
    app: test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
      - name: test
        image: openjdk:14
        ports:
        - containerPort: 8080
        volumeMounts: 
        - name: testing
          mountPath: "/usr/src/myapp/docker.jar"
        workingDir: "/usr/src/myapp"
        command: ["java"]
        args: ["-jar", "docker.jar"]        
      volumes: 
      - hostPath: 
          path: "C:\\Users\\user\\Desktop\\kubernetes\\docker.jar"
          type: File
        name: testing

I get the following error:

Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  19s                default-scheduler  Successfully assigned default/test-64fb7fbc75-mhnnj to minikube
  Normal   Pulled     13s (x3 over 15s)  kubelet            Container image "openjdk:14" already present on machine
  Warning  Failed     12s (x3 over 14s)  kubelet            Error: Error response from daemon: invalid mode: /usr/src/myapp/docker.jar

When I remove the volumeMount it runs with the error unable to access docker.jar.

        volumeMounts: 
        - name: testing
          mountPath: "/usr/src/myapp/docker.jar"
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Yanir
  • 95
  • 9
  • There is a known bug(https://github.com/kubernetes/kubernetes/issues/59876) with Windows to track this issue which has been closed due to inactivity but people have found couple of workarounds to resolve the problem. You could try to modify the path to `/C/Users/user/Desktop/kubernetes/docker.jar` which have worked for some. You could give it a try: – Krishna Chaurasia Feb 02 '21 at 06:52
  • I tried the solution , the problem is that kubernetes does not recognizes it as a file now, so when it uploads it to the machine, I don't know what it uploads and probably creates a default file and not my file. Since it is a windows problem I will try to deploy it in a linux machine. Thank you!!!! – Yanir Feb 02 '21 at 11:28

1 Answers1

1

This is a community wiki asnwer. Feel free to expand it.

That is a known issue with Docker on Windows. Right now it is not possible to correctly mount Windows directories as volumes.

You could try some of the workarounds mentioned by @CodeWizard in this github thread like here or here.

Also, if you are using VirtualBox, you might want to check this solution:

On Windows, you can not directly map Windows directory to your container. Because your containers are reside inside a VirtualBox VM. So your docker -v command actually maps the directory between the VM and the container.

So you have to do it in two steps:

Map a Windows directory to the VM through VirtualBox manager Map a directory in your container to the directory in your VM You better use the Kitematic UI to help you. It is much eaiser.

Alternatively, you can deploy your setup on Linux environment to completely omit those specific kind of issues.

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37