Search code examples
kuberneteskubectlcpvolumes

How to copy all data from an empty dir volume to my local machine?


I have a container with an empty dir volume

 - volumes:
   emptyDir: {}
   name: someName

I would like to copy all data to my machine using kubectl cp.

I do not know where the someName volume is located. How can I find out and how can I copy the data from the volume to my local machine?


Solution

  • You have to check in your pod where the volume is mounted. Check in the container sections, for a mount with the name someName, e.g:

    containers:
      volumeMounts:
      - name: someName
        mountPath: "/mnt/path"
    

    So you know that the emptyDir is mounted at the given mountPath.

    Afterwards you can copy the files via

    kubectl cp my-namespace/my-pod:/mnt/path /tmp/local/path