yunlee
yunlee

Reputation: 89

kubectl cp from a completed pod to local computer

I would like to use kubectl cp to copy a file from a completed pod to my local host(local computer). I used kubectl cp /:/ , however, it gave me an error: cannot exec into a container in a completed pod; current phase is Succeeded error. Is there a way I can copy a file from a completed pod? It does not need to be kubectl cp. Any help appreciated!

Upvotes: 2

Views: 5848

Answers (3)

Bagesh Sharma
Bagesh Sharma

Reputation: 889

Below command worked for me. I provided file name at destination like abc.txt

kubectl cp -n default kafka-0:/home/appuser/myfile.txt abc.txt

Upvotes: -2

aude
aude

Reputation: 1872

You can find the files, because the containers of a pod in the state Completed are not deleted, they are just not running.

I am not aware of any way to do it via Kubernetes itself, but here is how to do it if your container runtime is Docker:

$ ssh <node where the pod is>
$ docker ps -a | grep <pod name>
$ docker cp <pod name>:/your/files ./

The files in containers are just overlayfs mounts; if the container still exists, the files still exist.

So if you are using containerd runtime or something else, look at /var/lib/containers or something (don't know where different runtimes do their overlayfs mounts, but it can't not be at the node. you could check if you find out where via $ mount).

Upvotes: 2

Turing85
Turing85

Reputation: 20185

Nope. If the pod is gone, it's gone for good. Only possibility would be if the data is stored in a PV or some other external resource. Pods are cattle, not pets.

Upvotes: 6

Related Questions