3

I need to copy a zip file from my host machine to pod/container. for that using hostPath volume as follows

    volumeMounts:
    - mountPath: "/tmp/delivery/AB_Database.zip"
      name: db-volume
      subPath: AB_Database.zip
  volumes:
  - name: db-volume
    hostPath:
      path: /delivery/oracle 

but when I check inside pod AB_Database.zip is seen as directory.

  • A `hostPath:` mount looks for a file on the node the pod is running on. That's usually not your local system, and different replicas of the same deployment can be running on different nodes. I'd try to avoid a `hostPath:` mount in almost all cases, except for some admin-related things that run in DaemonSets. – David Maze Mar 07 '22 at 17:00

1 Answers1

0

It's due you have given name in subpath

volumeMounts:
    - mountPath: "/tmp/delivery/AB_Database.zip"
      name: db-volume
      subPath: AB_Database.zip
  volumes:
  - name: db-volume
    hostPath:
      path: /delivery/oracle 

Subpath work like

volumeMounts:
- name: test-path
  mountPath: /a/b/c
  subPath: d

inside c directory you have some files 1.txt, 2.txt thn subpath will rewrite those content in c and create new directory d

You can check more at : https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath

if you just want to mount the zip into the POD you can do something like with mountpath

- mountPath: /var/local/aaa/1.txt
  name: myfile

https://kubernetes.io/docs/concepts/storage/volumes/#hostpath-fileorcreate-example

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102