Run a pod with tar and try to push file into the mount point

4/27/2021

Our basic need is to check whether we are able to copy/push a file to a mountpoint or not. For this, I am advised to run a pod with tar and try to push file into the mount point. I have searched through the web and got the following commands:
-> kubectl cp [file-path] [pod-name]:/[path] (Although not giving any error but this command is not working and the file is not visible in the mentioned location.)

-> Verified the absence of file in the remote pod using the following command:

 kubectl exec <pod_name> -- ls -la /  

-> Found the below command that uses tar options but I don't want to exclude any file and hence not sure how to proceed with this:

kubectl exec -n <some-namespace> <some-pod> -- tar cf - --exclude='pattern' /tmp/foo | tar xf - -C 
   /tmp/bar  

-> Is there any other tar option that can help me in pushing the file to the mountpoint?
Also, the kubectl cp help command says that tar binary must be present for copy to work. Maybe this is the reason why I am unable to copy. But, I don't know how to check the tar binary's presence and how to get it if it's not there. Please help me with this.

-- Muskan Sharma
kubernetes
kubernetes-pod
mount-point
push
tar

1 Answer

4/27/2021

I'm not sure why cp command not worked for you. However I tried to add a tar file inside the pod and it worked.

I used the following command:

kubectl cp ./<TAR FILE PATH> <NAMESPACE>/<POD NAME>:/<INSIDE POD PATH>

It's not best practice to add a file like this to a pod. You can also init a container or add the file during the build process of the docker image. You can also alternatively use a volume mount.

-- Harsh Manvar
Source: StackOverflow