Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy files from pod to local #193

Open
bboysoulcn opened this issue Oct 23, 2023 · 10 comments
Open

Copy files from pod to local #193

bboysoulcn opened this issue Oct 23, 2023 · 10 comments
Labels
enhancement New feature or request

Comments

@bboysoulcn
Copy link

Which project are you requesting an enhancement for?

kr8s

What do you need?

Copy files from pod to local

@bboysoulcn bboysoulcn added the enhancement New feature or request label Oct 23, 2023
@jacobtomlinson
Copy link
Member

This would be great. It looks like kubectl uses the exec API to implement this so we would need to implement #169 before we could do this.

@jacobtomlinson
Copy link
Member

jacobtomlinson commented Nov 21, 2023

Now that Pod.exec() is available in v0.11.0 we can do things like copying individual files locally via stdout.

import kr8s

# Copy file from my-pod:/etc/os-release to /tmp/os-release
with open("/tmp/os-release", "wb") as fh:
    pod = kr8s.objects.Pod.get("my-pod")
    pod.exec(["cat", "/etc/os-release"], stdout=fh)

Copying in the other direction seems to be trickier due to #212. If we can find a workaround to this then we could implement a Pod.cp() convenience method and make more use of tar to enable copying whole directories (see #210 (comment)).

@bboysoulcn
Copy link
Author

Thank you for your contribution

@marcio-pessoa
Copy link

I never found a solution to this problem, so I finally wrote an application to copy files without tar.
It is just a beta, but is working fine on my environment.

https://github.com/marcio-pessoa/kubectl-cp

@jacobtomlinson
Copy link
Member

@marcio-pessoa neat! Looking over the code it looks like it requires sh, cat, tee, find and mkdir to all be present and on the path in the remote container. So you wouldn't be able to use it on a container like scratch. I'm curious which container images you see which have all of those binaries, but not tar?

@marcio-pessoa
Copy link

I'm sorry @jacobtomlinson .
I thought I could help in some way.

@jacobtomlinson
Copy link
Member

Sure, please don't take offence to my question. I was just curious about the use case for your project?

@marcio-pessoa
Copy link

marcio-pessoa commented Apr 23, 2024

No problem.

I have some examples, but I can't use them all because of my contract.
But it is a RedHat practice. I also recently worked with container by Oracle without tar.

But Keycloak is a good example.

quay.io/keycloak/keycloak

However, your project, the kr8s library is extremely elegant and is probably the best way to solve the problem currently.

@jacobtomlinson
Copy link
Member

Ah that's interesting. Yeah it looks like any container built from registry.access.redhat.com/ubi9-micro doesn't have tar, but it does have the other binaries you are depending on.

I wonder if we could go in a totally different direction and use an EphemeralContainer instead. We would make the image configurable but default to something very small that does contain the dependencies necessary for copying files. That way we could even support scratch based distroless images and still copy files in/out.

@marcio-pessoa
Copy link

Until the official kubectl cp does not have the definitive solution for copying files in scratch containers, the approach suggested by @jacobtomlinson using EphemeralContainer is probably the almost ultimate solution.

Let's work together to make this dream come true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants