Unable to delete all files from directory

12/30/2019

I want to delete all the files under the volume directory. The directory is inside the Kubernetes pod. So I am using the exec command.

My command -

kubectl exec $POD -- rm -rf /usr/local/my-app/volume/*

The above command is not working. No output of the above command on terminal. I tried with below command and it is working -

kubectl exec $POD -- rm -rf /usr/local/my-app/volume

But it will delete the directory. I can't delete the directory because it is using for mounting purpose.

How can I achieve the above functionalities?

Thanks

-- lucy
bash
exec
kubernetes
linux
rm

1 Answer

12/31/2019

That's because the wildcard expansion is happening on your machine and not the Pod; what you want is to have the shell glob expand on the Pod, which one can accomplish via

kubectl exec $POD -- sh -c 'rm -rf /usr/local/my-app/volume/*'
-- mdaniel
Source: StackOverflow