How can I copy files from a Kubernetes node to my local machine?

0
19
Asked By TechWhiz92 On

I'm trying to copy files or directories from a Kubernetes node to my local device. I've been using a tool that lets me access the node shell interactively, but now I want to extract some logs using a command like: `k node-shell mynode -- tar -czf- /var/log/... > o.tgz`. However, I'm running into an issue because `tar` won't write to a tty, giving me an error about missing the -f option. I tried a workaround using a shell command, but it seems to corrupt the binary data when I try to extract it. I also attempted using a different approach with `k debug`, but that ends up adding unwanted stderr into my tar file. Is there a direct method to get a binary stream from the node without using `ssh`?

3 Answers

Answered By NodeNinja73 On

Have you thought about using a busybox pod? You could mount the node path you need and then use `kubectl cp` to easily grab the files directly from the container. It should simplify the process!

QuerySeeker88 -

That sounds interesting! I'm just looking for a single command that would let me pipe the data directly, like you do with `ssh root@ip tar -czf- ... | tar -xzf-`. Any thoughts on that?

Answered By DataDynamo22 On

If you're mainly after logs, there are better ways to stream them without copying files directly. You might want to explore the built-in logging capabilities of Kubernetes instead. Also, just a heads-up, `kubectl cp` does the job for getting files from containers, but it can't be used directly to copy logs from the node itself.

LostInLogs11 -

I thought `kubectl cp` only works for containers, can you clarify if there's a way to extract logs from a node this way?

Answered By ShellSorcerer44 On

You might want to look into whether your plugin has a no tty option available. If not, using the `script` command might be a good workaround for this situation!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.