Kubectl copy files from remote to local system Vice Versa
Table of Contents
How to copy files from kubernate pods into windows/linux system by using the kubectl command. Here there is no issue while using the linux system local path because linux path not having any Drive name but in the windows file system path having the Drive name so due to this Drive name you will get the error : src doesn’t exist in local filesystem
Kubectl Copy from Remote to Local:
syntax C:\Users\narayanatutorial>kubectl cp <name-space>/<pod-name>:<remote-path> <local-path> Example Windows C:\Users\narayanatutorial>kubectl cp NTNameSpace/NTPOD:/home/narayanatutorial/log D:/logs/ Linux /home/users/narayanatutorial$ kubectl cp NTNameSpace/NTPOD:/home/narayanatutorial/log /home/logs/
Linux :
Path : /home/logs
In the linux path there is no any issue
Window:
D:/logs
Here kubectl is treating the D: as a pod named D and not finding it. So remove the drive letter and use a relative path is successful like as follows
Windows path is C:\Users\narayanatutorial> here you can create the folder like logs under narayanatutorial folder and give the relative path is logs
Windows
C:\Users\narayanatutorial> kubectl cp NTNameSpace/NTPOD:/home/narayanatutorial/log logs/
Kubectl Copy from Local to Remote:
syntax C:\Users\narayanatutorial> kubectl cp <local-path> <name-space>/<pod-name>:<remote-path> Example Windows C:\Users\narayanatutorial> kubectl cp D:/logs/ NTNameSpace/NTPOD:/home/narayanatutorial/log Linux /home/users/narayanatutorial$ kubectl cp /home/logs/ NTNameSpace/NTPOD:/home/narayanatutorial/log
Linux :
Path : /home/logs
In the Linux path there is no any issue
Window:
D:/logs
Here kubectl is treating the D: as a pod named D and not finding it. So remove the drive letter and use a relative path is successful like as follows
Windows path is C:\Users\narayanatutorial> here you can create the folder like logs under narayanatutorial folder and give the relative path is logs
Windows
C:\Users\narayanatutorial>kubectl cp logs/ NTNameSpace/NTPOD:/home/narayanatutorial/log
Copy Files from a docker container to your machine
Just change kubectl to docker and it will work as well.
Windows C:\Users\narayanatutorial>docker cp NTNameSpace/NTPOD:/home/narayanatutorial/log logs/ Linux /home/users/narayanatutorial$ docker cp NTNameSpace/NTPOD:/home/narayanatutorial/log /home/logs/
Copy Files from a Local system to docker container
Just change kubectl to docker and it will work as well.
Windows C:\Users\narayanatutorial>docker cp logs/ NTNameSpace/NTPOD:/home/narayanatutorial/log Linux /home/users/narayanatutorial$ docker cp /home/logs/ NTNameSpace/NTPOD:/home/narayanatutorial/log
Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in the IT industry for more than 12 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting, Website Development, and IAM(ForgeRock) Specialist
I am a self-learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.