Resolved: Why Kubernetes mounted volume files turning into directory inside the pod

Question:

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.

Answer:

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

If you have better answer, please add a comment about this, thank you!