9

After creating a new app using oc new-app location/nameofapp, many things are created: a deploymentConfig, an imagestream, a service, etc. I know you can run oc delete <label>. I would like to know how to delete all of these given the label.

womplefrog
  • 769
  • 1
  • 6
  • 18

1 Answers1

22

When using oc new-app, it would normally add a label on each resource created call app with value being the name given to the application. That name would be based on the name of the git repository, or could have been supplied using the --name option. Knowing that to delete everything you can then run:

oc delete all --selector app=appname

Before you delete anything you should be able to check what would matche by running:

oc get all --selector app=appname

Note that if creating from a template, rather than a repository, how things are labelled can depend on what the template itself sets up, so the instructions above may not apply.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • Also, do you mind voting this question up? The online OpenShift documentation doesn't do a great job of explaining this. I'm sure this would help other out. – womplefrog Aug 13 '16 at 18:51
  • 2
    also, I believe running 'oc scale dc --replicas=0' is prudent prior to deleting all of the resources. wouldn't you agree? – womplefrog Aug 15 '16 at 17:00
  • 1
    Personally I never bother to scale down to 0 replicas first, but then these are throw away applications for me. So the platform itself doesn't care if you don't stop things first, it will stop containers in the same way that would occur if scaled down. That is, signal sent to container to stop it, allowing the application to shutdown in an orderly manner if need be. – Graham Dumpleton Aug 15 '16 at 23:48
  • Ahhh. I know when shutting things down manually in the web app, funky things occur if you delete config files or instances before scaling down the app itself. For example, I've deleted some instances and then the replication controller would simply create another instance. – womplefrog Aug 16 '16 at 17:38
  • Possibly, it probably doesn't apply any sort of algorithm to determine a sensible order to delete things in. – Graham Dumpleton Aug 16 '16 at 23:30