<p>Instead of using Kubernetes' <code>default</code> namespace, it's a good practice to xreate separate namespaces for each of your applications or each logical component of your infrastructure.</p>
<p>OReilly's &quot;Cloud Native DevOps with Kubernetes&quot; highlights a relevant potential risk:</p>
<blockquote>
<p>You could use a namespace as a kind of temporary virtual cluster, and delete the namespace when you’re finished with it. But be careful! Deleting a namespace deletes all the resources within it. You really don’t want to run that command against the wrong namespace.
(...)
So don’t delete namespaces unless they really are temporary, and you’re sure they don’t contain any production resources.</p>
</blockquote>
<p>In <a href="https://kubernetes.io/docs/tasks/administer-cluster/namespaces/#deleting-a-namespace" rel="nofollow noreferrer">Kubernetes' documentation</a> on namespaces, I read a similar warning:</p>
<blockquote>
<p>Warning: This deletes everything under the namespace!</p>
</blockquote>
<p>Of course we need to be careful, but it's a scary thought that resources can be deleted this easily.
Is there any way to get a warning about which resources will be removed with:
<code>kubectl delete namespaces &lt;ns-name&gt;</code>?</p>

Casper Dijkstra
<p>When you delete a namespace, all namespaced resources in this namespace will be deleted. There's no direct way to list all the resources in a namespace (<code>kubectl get all</code> lists only a selected set of resources).</p>
<p>However, you can enumerate all namespaced <em>resource types</em> with:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl get api-resources --namespaced=true
</code></pre>
<p>And you can then iterate through these resource types and check if you have any instances of them in your namespace with <code>kubectl get</code>.</p>
<p>For example, the following command lists all resources in the <code>ns-name</code> namespace:</p>
<pre class="lang-sh prettyprint-override"><code>for r in $(kubectl api-resources --namespaced=true --no-headers 2&gt;/dev/null | cut -d ' ' -f 1); do 
  kubectl get &quot;$r&quot; -n ns-name --no-headers -o custom-columns=:.metadata.name | sed &quot;s/^/$r /&quot;
done
</code></pre>
<p>And this are all the resources that will be deleted when you delete the <code>ns-name</code> namespace.</p>
