<p>I have many pods in a kubernetes system with randomly name wordpress.xxx.xx.</p>

<p>Here the list of <a href="https://i.stack.imgur.com/k7Jxw.png" rel="nofollow noreferrer">pods</a></p>

<p>I want to use one command with <code>kubectl cp</code> in other to copy files to all pods from one deployment.</p>

<p>In my case I don't want to use volumes because they mount into a path that already the existing content of that folder will be hidden.</p>

<p>How to do that, please?</p>

<p>Thank you for your answer.</p>

<p>The <code>kubectl cp</code> command copies files to a single container in a pod. To copy files in multiple containers easily, the below shell script can be used.</p>

<pre><code>for pod in `kubectl get pods -o=name | grep wordpress | sed "s/^.\{4\}//"`; do echo "copying to $pod"; kubectl cp file.txt $pod:/; done
</code></pre>

<p>or</p>

<pre><code>for pod in `kubectl get pods -o=name | grep wordpress | sed "s/^.\{4\}//"`
do
    echo "copying file to $pod"
    kubectl cp file.txt $pod:/
done
</code></pre>

<p>Both the scripts are same, single vs multi-line.</p>
