I have many pods in a kubernetes system with randomly name wordpress.xxx.xx.
Here the list of pods
I want to use one command with kubectl cp
in other to copy files to all pods from one deployment.
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.
How to do that, please?
Thank you for your answer.
The kubectl cp
command copies files to a single container in a pod. To copy files in multiple containers easily, the below shell script can be used.
for pod in `kubectl get pods -o=name | grep wordpress | sed "s/^.\{4\}//"`; do echo "copying to $pod"; kubectl cp file.txt $pod:/; done
or
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
Both the scripts are same, single vs multi-line.