kubernetes: kubectl cp command fails passing full Windows path as target

What happened: Running the following command in Windows fails: kubectl cp -n test -c [container] [pod]:/log “d:/log”

What you expected to happen: error: src doesn’t exist in local filesystem

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version): 1.14
  • Cloud provider or hardware configuration:
  • OS (e.g: cat /etc/os-release): Windows
  • Kernel (e.g. uname -a):
  • Install tools:
  • Network plugin and version (if this is a network-related bug):
  • Others:

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (4 by maintainers)

Most upvoted comments

I’m having the same problem. Any fix or workaround?

Yes, I tried with a relative path for the target location temp/start_4.51.hprof, instead of C:\temp\start_4.51.hprof and it worked

PS C:\> kubectl cp <pod_name>:/tmp/4.51.prof c:/temp/start_4.51.hprof error: src doesn't exist in local filesystem

However, PS C:\> kubectl cp <pod_name>:/tmp/4.51.prof temp/start_4.51.hprof tar: removing leading '/' from member names

The file gets downloaded successfully

If anyone uses windows pods, it may be hard to get files copied to the pods from local machine with those linux paths for kubectl cp command:

Procedure to copy files from local machine to kubernetes pod: (especially windows container)

I want to copy node.aspx from my local machine to podname:\c:\inetpub\wwwroot First upload Node.aspx to your cloud drive, path will be /home/{your_username} in my case /home/pranesh Then find out the pod name, in my case its aspx-deployment-84597d88f5-pk5nh, follow below command PS /home/pranesh> kubectl cp /home/pranesh/Node.aspx aspx-deployment-84597d88f5-pk5nh:/Node.aspx This copies the file to c drive of container, then move file from c drive to required path with powershell

PS /home/pranesh> kubectl exec aspx-deployment-84597d88f5-pk5nh powershell "Copy-Item "C:\Node.aspx" -Destination "C:\inetpub\wwwroot"" Use the reverse procedure for copying from container to cloud drive and download.