Trying to copy files to Pods with `kubectl cp`, But getting Error: unknown flag: --all-namespaces

8/12/2019

Trying to copy and execute a bash script in a POD (which has one container)

kubectl cp ../docker/scripts/upload_javadumps.sh ${POD}:/opt -n apm

This commands works perfectly, But we have multiple Namespaces, Hence I wanted to use --all-namespaces like shown below which errors out saying, Error: unknown flag: --all-namespaces

How Do I use --all-namspaces in kubectl cp command?

kubectl cp ../docker/scripts/upload_javadumps.sh  ${POD}:/opt --all-namespaces
echo "Successfully copied the upload_javadumps.sh script"```
-- Suresh Ravi
bash
docker
kubernetes

1 Answer

8/12/2019

For kubectl cp flag --all-namespaces doesn't exist, you can check it with kubectl cp -h.

In your case I would go with simple bash loop like this:

for ns in namespace1 namespace2; do kubectl cp ../docker/scripts/upload_javadumps.sh ${POD}:/opt -n $ns;done
-- FL3SH
Source: StackOverflow