Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does kubectl cp command terminates with exit code 126?

I am trying to copy files from the pod to local using following command:

kubectl cp /namespace/pod_name:/path/in/pod /path/in/local

But the command terminates with exit code 126 and copy doesn't take place.

Similarly while trying from local to pod using following command:

kubectl cp /path/in/local /namespace/pod_name:/path/in/pod

It throws the following error:

OCI runtime exec failed: exec failed: container_linux.go:367: starting container process caused: exec: "tar": executable file not found in $PATH: unknown

Please help through this.

like image 533
kkpareek Avatar asked Dec 01 '22 08:12

kkpareek


2 Answers

kubectl cp is actually a very small wrapper around kubectl exec whatever tar c | tar x. A side effect of this is that you need a working tar executable in the target container, which you do not appear to have.

In general kubectl cp is best avoided, it's usually only good for weird debugging stuff.

like image 129
coderanger Avatar answered Dec 04 '22 02:12

coderanger


An alternative way to copy a file from local filesystem into a container:

cat [local file path] | kubectl exec -i -n [namespace] [pod] -c [container] "--" sh -c "cat > [remote file path]"
like image 42
Yoni Sade Avatar answered Dec 04 '22 03:12

Yoni Sade