How to use kubectl cp to copy files automatically from a local system to kubernetes Pods with list filter How to use kubectl cp to copy files automatically from a local system to kubernetes Pods with list filter kubernetes kubernetes

How to use kubectl cp to copy files automatically from a local system to kubernetes Pods with list filter


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.