# Delete namespace and all its contents

**URL:** <https://discourse.sensu.io/t/delete-namespace-and-all-its-contents/2357>\
**Category:** Sensu Go\
**Tags:** sensu-go, sensuctl\
**Created:** [December 18, 2020, 6:23pm UTC](https://discourse.sensu.io/t/delete-namespace-and-all-its-contents/2357 "2020-12-18T18:23:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![swapzero](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/swapzero/32/529_2.png) [@swapzero](https://discourse.sensu.io/u/swapzero)\
**Post date:** [December 18, 2020, 6:23pm UTC](https://discourse.sensu.io/t/delete-namespace-and-all-its-contents/2357/1 "2020-12-18T18:23:34Z")

</div>

Is there a way to delete entire namespace and all the contents in the namespace such as checks, handlers, users associated with the namespace via a single sensuctl command.

Currently trying to clear a namespace with some items requires to individually clear out the various elements which can be tedious before we can run the `sensuctl namespace delete xyz` command.

---

<div class="post-metadata">

**Author:** ![ohhfine](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/ohhfine/32/434_2.png) [@ohhfine](https://discourse.sensu.io/u/ohhfine)\
**Post date:** [December 19, 2020, 8:25pm UTC](https://discourse.sensu.io/t/delete-namespace-and-all-its-contents/2357/2 "2020-12-19T20:25:30Z")

</div>

You might be able to dump that namespace to a file then use sensuctl delete -f

---

<div class="post-metadata">

**Author:** ![majormoses](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/majormoses/32/62_2.png) [@majormoses](https://discourse.sensu.io/u/majormoses)\
**Post date:** [December 27, 2020, 8:20pm UTC](https://discourse.sensu.io/t/delete-namespace-and-all-its-contents/2357/3 "2020-12-27T20:20:31Z")

</div>

`sensuctl` has a few mechanisms for doing that, you can use the `delete` method which works, I might suggest looking at the newer `prune` method as well.

> **[Sensu | Keep your configs in good order with sensuctl prune 🌿](https://sensu.io/blog/keep-your-configs-in-good-order-with-sensuctl-prune)**
>
> We’re excited to share our first-ever alpha feature: sensuctl prune, which will help you easily (and safely!) remove resources you no longer need.

---

<div class="post-metadata">

**Author:** ![swapzero](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/swapzero/32/529_2.png) [@swapzero](https://discourse.sensu.io/u/swapzero)\
**Post date:** [December 29, 2020, 3:05pm UTC](https://discourse.sensu.io/t/delete-namespace-and-all-its-contents/2357/4 "2020-12-29T15:05:38Z")

</div>

This is a good way to delete the regular checks and handlers but with users created in the namespace, the dump doesnot provide with just users of the single namespace. It infact returns all the users across all namespaces. My command `sensuctl --namespace automation dump all -f out.yaml` returned all namespaces regardless of the namespace filter while specifically going `sensuctl --namespace automation dump checks,handlers,filters,users -f out.yaml` still gave users from other namespaces as well. It would be helpful to know after deleting resources in the namespace, what remains to be deleted.

In my case i did find that the following command almost always cleared all the resources in the namespace  
`sensuctl --namespace automation dump checks,handlers,filters,assets -f out.yaml`  
`sensuctl delete -f out.yaml`  
`senuctl namespace delete automation`
