Reputation: 8724
I would like to execute a chown
command on all my php-fpm pods.
I came to this part:
#!/bin/bash
PODS=$(kubectl get pods -n my-production | grep php-fpm | awk -F' *|/' '$2 == $3 && $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"
This is entering each specific pod that has a "php-fpm" in its name.
I would like to execute a chown command for each of those pods.
The command that I should run looks like this:
chown -R www-data:www-data /var/app/current/app/cache
Upvotes: 0
Views: 456
Reputation: 15312
Just replace the command in your script:
#!/bin/bash
PODS=$(kubectl get pods -n my-production | grep php-fpm | awk -F' *|/' '$2 == $3 && $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"
Since you execute a non-interactive command, you don't need the -it
flags and since the command has arguments, you need a --
between the kubectl command and the command that you want to run on the Pods.
Upvotes: 2