<p>I would like to execute a <code>chown</code> command on all my php-fpm pods.</p>

<p>I came to this part:</p>

<pre><code>#!/bin/bash
PODS=$(kubectl get pods -n my-production | grep php-fpm | awk -F' *|/' '$2 == $3 &amp;&amp; $4 == "Running"' | awk {'print $1'} | column -t )
for POD in $PODS
do
    echo $POD
    kubectl -n my-production exec -it $POD -c php /bin/bash
done

echo "all done"
</code></pre>

<p>This is entering each specific pod that has a "php-fpm" in its name.</p>

<p>I would like to execute a chown command for each of those pods.</p>

<p>The command that I should run looks like this:</p>

<p><code>chown -R www-data:www-data /var/app/current/app/cache</code></p>

Bob
<p>Just replace the command in your script:</p>

<pre class="lang-sh prettyprint-override"><code>#!/bin/bash
PODS=$(kubectl get pods -n my-production | grep php-fpm | awk -F' *|/' '$2 == $3 &amp;&amp; $4 == "Running"' | awk {'print $1'} | column -t )
for POD in $PODS
do
    echo $POD
    kubectl -n my-production exec $POD -c php -- chown -R www-data:www-data /var/app/current/app/cache
done

echo "all done"
</code></pre>

<p>Since you execute a non-interactive command, you don't need the <code>-it</code> flags and since the command has arguments, you need a <code>--</code> between the kubectl command and the command that you want to run on the Pods.</p>
