How to delete files/directories using oc cli in Openshift

Viewed 2058

I've used oc cp to copy files and directories onto a persistent volume attached to a pod in my openshift project. Is there any way to delete?

2 Answers

You can use oc exec to execute any command inside the container, so you can use the following to execute rm within the container to delete files:

oc exec <pod-name> rm /path/to/my-file

or to recursively delete a folder within the container:

oc exec <pod-name> rm -rf /path/to/my/directory

Alternatively, you can use oc rsh <pod-name> to open an interactive terminal if the Pod contains a shell binary.

You can delete a persistent volume with:

oc delete pv the-name-of-the-persistent-volume

so for example

oc delete pv grafana-data

You can get the list of persistent volumes with:

oc get pv.

Related