Full lesson
Explore the full explanation, examples, and visuals at your own pace.
Terminal: the cleanup command
One command deleted every app in the namespace. A developer, cleaning up, runs kubectl delete namespace dev, expecting a label to disappear. The terminal says dev is deleted. Then kubectl get deployments in dev finds nothing at all. The app is gone, and that's a surprise worth understanding.
$ kubectl delete namespace dev
namespace "dev" deleted
$ kubectl get deployments -n dev
No resources found in dev namespace.The namespace holds the objects
The reason is that a namespace isn't a label. It's a container. Inside dev, you have a Deployment, which runs the web app, and a Service, which gives it a network address. There's also a ConfigMap for settings and a Secret, which stores the password. Each of these lives inside the dev namespace.
Delete the box, lose the contents
On the left, the dev namespace holds four objects: the Deployment, Service, ConfigMap and Secret. Run kubectl delete namespace dev, and the right side shows the result. The box is gone, and so is everything in it. The app, its network entry, its config and its password all disappear together.
Fix: look inside before you delete
Before deleting, list what's inside. This command asks for everything in the dev namespace. Notice we name configmaps and secrets explicitly, because get all skips them. The output shows the Deployment, Service, ConfigMap and Secret. Now you can decide whether deleting all of that is really what you intend.
$ kubectl get all,configmaps,secrets -n dev
# illustrative output, trimmed
deployment.apps/web
service/web
configmap/web-config
secret/db-passwordA namespace isn't a tag. It's the box everything lives in.
A namespace isn't a tag. It's the box everything lives in. So before you delete one, always list its contents first, and know what's inside.

