Quantcast
Channel: Copy multiple files using * wildcard from kubernetes container - DevOps Stack Exchange
Viewing all articles
Browse latest Browse all 6

Answer by W Goldfarb for Copy multiple files using * wildcard from kubernetes container

$
0
0

I had a similar requirement and finally settled on:

mkdir /my/dest/dirkubectl  exec $TARGET_POD -n MYNAMESPACE -- tar -zcvf - -C /my/src/directory . | tar -zxvf - -C /my/dest/dir

This depends on 'tar' being available inside the container. Similar can be done with any archive command (zip/unzip or cpio) that can deal with stdin/stdout as long as the command is in both the container and the host.

Also note that '*' is not native to tar, but depends on shell expansion (in my experience...), so if you want to match only certain files in a directory on the container I include 'bash' in the call and cd to the directory first:

kubectl  exec $TARGET_POD -n MYNAMESPACE -- bash -c "cd /my/src/directory;tar -zcvf - *.log" | tar -zxvf - -C /my/dest/dir

Again, bash or some other shell supporting * expansion must be present in the container.

Finally, this works in the other direction as well sending multiple files to a container:

cd /my/src/dirtar -zcvf - *.log | kubectl exec $TARGET_POD -n MYNAMESPACE --stdin -- tar -zxvf - -C /my/dest/dir

And "bash" is your friend if the target directory does not exist:

tar -zcvf - *.log | kubectl exec $TARGET_POD -n MYNAMESPACE --stdin -- bash -c "mkdir -p /my/dest/dir;tar -zxvf - -C /my/dest/dir"

Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images