I'm trying to copy files from Kubernetes Pods to my local system. I am getting the below error while running following command:
kubectl cp aks-ssh2-6cd4948f6f-fp9tl:/home/azureuser/test.cap ./test.cap
Output:
tar: home/azureuser/test: Cannot stat: No such file or directory tar: Exiting with failure status due to previous errors error: home/azureuser/test no such file or directory
I could see the file under above given path. I am really confused.
Could you please help me out?
You can mount a local directory into the pod.
Update your aks-ssh yaml file:
Now you can access your files in the local directory.
As stated in
kubectl
help:You can also login to your
Containter
and check if file is there:If this still doesn't work, try:
Consider advice of kchugalinskiy here #58692.
Let's say you are copying file from bin folder to local system. The command is
You can connect to POD to verify if you are specifying correct file name
kubectl cp will not work if your container does not have tar command in the PATH. From your error it sees like tar command is not available on your container. https://github.com/kubernetes/kubernetes/issues/58512 Please explore other options
I resolve this problem by set the source folder to be relative path. If the file location is /home/azureuser/test.cap, and working dir is /home/azureuser/, the cmd is
kubectl cp aks-ssh2-6cd4948f6f-fp9tl:test.cap ./test.cap