Delete All Apps and Services in Specific Space
Is There a Foundry Script or Command to Cleanup All Space Apps/Services, the Problem That We Have Many Apps Which Is Related to Services and You Cannot Delete...
Is there a foundry script or command to cleanup all space apps/services, the problem that we have many apps which is related to services and you cannot delete them until you delete all apps, is there any script or command which can help ?
I dont want to hard-code all the apps and services, is there a way for a given space delete all apps and services instances? is it possible to make mass delete for services?
2 Answers
The easiest thing would be to cf delete-space, wait for that to finish, then cf create-space to remake your space. The cf delete-space is recursive so it would delete everything in that space.
The only challenge might be if you have lots of people invited to your space, this would delete the space so their access would be removed and you'd need to add that back after you recreate the space.
Aside from that, you're going to need to script it.
I would try this order:
- grab all the apps in the space
- for each app
- delete the app (this should also delete service bindings)
- grab all of the service instances in the space
- if you use service keys, for each service
- check for service keys, if present delete them
- for each service instance, delete the instance
- if you use service keys, for each service
- run
cf delete-orphaned-routes, that should clean up all the routes left behind
alternatively, you could use cf delete -r when you delete the app and it will delete the routes associated as well.
As far as how you get "all the apps" or "all the services", you could do something like cf apps | tail +5 | awk '{print $1}' or cf services | tail +4 | awk '{print $1}', or you could use cf curl and the API. The API will be a little trickier though because you have to deal with paging (or maybe not, if you don't have that many apps/services).
You cannot delete all App from Cloudfoundry in a single shot. Cloudfoundry document doest not explain a way to delete all App.
You can delete one App at a time in cloudfoundry. Please refer below link to delete an APP.Click here
Many apps use services and routes. Deleting an app does not delete the services used by the app, and you must explicitly remove routes between your app and the Internet.