Error while copying local file to k8s container

5/18/2018

I am trying to copy a jar file to specific pod's container by executing below command.

kubectl cp local_policy.jar podname:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/lib/security.

I am getting below error.

rpc error: code = 13 desc = invalid header field value "oci runtime error: exec failed: container_linux.go:247: starting container process caused \"exec: \\\"tar\\\": executable file not found in $PATH\"\n"

Please help.

-- Sudhir
kubectl
kubernetes

2 Answers

6/20/2019

Just install tar binary in the container to/from which you want to copy files. This will allow the kubectl command to copy files from your local machine to the target container. On Amazon linux you can install it via yum

yum install tar
-- Amrut Prabhu
Source: StackOverflow

5/18/2018

tar binary is necessary to run cp. It is in the help page of kubectl cp:

kubectl cp --help
Copy files and directories to and from containers.

Examples:
  # !!!Important Note!!!
  # Requires that the 'tar' binary is present in your container
  # image.  If 'tar' is not present, 'kubectl cp' will fail.
-- Ignacio Millán
Source: StackOverflow