Full lesson
Explore the full explanation, examples, and visuals at your own pace.
Terminal: deleting the web Deployment
You deleted your app. Half of it is still there. We ran kubectl delete deployment web, and the Deployment is gone, along with its Pods. But list everything again, and service web and configmap web-config are still sitting in the cluster. Why did those two survive?
$ kubectl delete deployment web
deployment.apps "web" deleted
$ kubectl get deploy,pods,svc,cm
# output trimmed to the web app
NAME TYPE CLUSTER-IP
service/web ClusterIP 10.96.12.4
NAME DATA
configmap/web-config 1Who owns what
The Deployment created a ReplicaSet, which is the object that keeps the right number of Pod copies running. The ReplicaSet created the Pods. So ownership runs down that chain. The Service only selects Pods by label, and the ConfigMap is just read by them. Neither one is owned by the Deployment.
Before vs after kubectl delete deployment web
On the left, all four objects are running. After kubectl delete deployment web, the Deployment and its Pods are gone, because deletion follows ownership links down. The Service web and the ConfigMap web-config are still standing. Nothing owns them, so nothing deletes them. They just sit there, quietly left behind.
Fix: delete with the file you applied
The fix is to delete with the same file you applied. Running kubectl delete -f app.yaml reads every object listed there, the ConfigMap, the Service, and the Deployment, and deletes each one. Things created together go away together. The Pods still disappear through ownership, when their Deployment is removed.
# app.yaml (specs trimmed)
kind: ConfigMap
metadata: {name: web-config}
---
kind: Service
metadata: {name: web}
---
kind: Deployment
metadata: {name: web}
$ kubectl delete -f app.yaml
configmap "web-config" deleted
service "web" deleted
deployment.apps "web" deletedKubernetes deletes what an object owns, not what you meant.
Kubernetes deletes what an object owns, not what you meant. So when you remove an app, delete with the same files you applied.
