<p>I have a use case where my pod is run as non-rootuser and its running a python app.
Now I want to copy file from master node to running pod. But when I try to run </p>

<pre><code>kubectl cp app.py 103000-pras-dev/simplehttp-777fd86759-w79pn:/tmp
</code></pre>

<p>This command hungs up but when i run pod as root user and then run the same command
it executes successfully. I was going through the code of kubectl cp where it internally uses tar command. </p>

<p>Tar command has got multiple flags like --overwrite --no-same-owner, --no-preserve and few others. Now from kubectl cp we can't pass all those flag to tar. Is there any way by which I can copy file using kubectl exec command or any other way.</p>

<pre><code>kubectl exec simplehttp-777fd86759-w79pn -- cp app.py /tmp/ **flags**
</code></pre>

prashant
<p>If the source file is a simple text file, here's my trick:</p>
<pre><code>#!/usr/bin/env bash

function copy_text_to_pod() {
  namespace=$1
  pod_name=$2
  src_filename=$3
  dest_filename=$4

  base64_text=`cat $src_filename | base64`
  kubectl exec -n $namespace $pod_name -- bash -c &quot;echo \&quot;$base64_text\&quot; | base64 -d &gt; $dest_filename&quot;
}

copy_text_to_pod my-namespace my-pod-name /path/of/source/file /path/of/target/file
</code></pre>
<p>Maybe base64 is not necessary. I put it here in case there is some special character in the source file.</p>
