I need to rsync a file tree to a specific pod in a kubernetes cluster. It seems it should be possible if only one can convince rsync that kubectl acts sort of like rsh. Something like:
rsync --rsh='kubectl exec -i podname -- ' -r foo x:/tmp
... except that this runs into problems with x since rsync assumes a hostname is needed:
exec: "x": executable file not found in $PATH
I can not seem to find a method to help rsync construct the rsh command. Is there a way to do this? Or some other method by which relatively efficient file transfer can be achieved over a pipe?
(I am aware of gcloud compute copy-files
, but it can only be used onto the node?)
To rsync to a pod I use the following helper:
I put this in a file called "rsync-helper.sh" and then run the rsync like this:
If you'd like a simple script that wraps this all up save this as krsync:
Then you can use krsync where you would normally rsync:
Or you can set the namespace:
NOTE: You must have rsync executable in the pod image for this to work.
In the end, I wrote a Python script to act as a receiver of tar files. You can do thus:
Note that this only works if you cluster nodes are kubernetes 1.1 or later.
If the
tar
binary is available on the container, you can transfer files using the newcp
command.Though possibly not as efficient as rsync.
A one-liner, just edit to you names and paths:
The answer from @karl-bunch was perfect. For those who prefer using
tar
this is how I use it:I ran into the same problem today. I had to sync files from the pod to my local machine.
My solution for this was this rsync command
It is not supported, but there is an issue for adding support which you can +1 or even contribute to: https://github.com/kubernetes/kubernetes/issues/18007#issuecomment-164797262