kubectl 1.37 reference · Basics
kubectl delete Command (kubectl)
Delete resources by name, file or label selector; deleting a namespace deletes everything inside it.
kubectl 1.37
Syntax
kubectl delete RESOURCE NAME | -f FILE | -l SELECTOR [--wait=false]
Parameters
| Parameter | Description |
|---|---|
-l SELECTOR |
Delete everything matching the labels. |
-f FILE |
Delete what a manifest describes. |
--wait=false |
Return without waiting for finalizers. |
--grace-period=N |
Override the termination grace period. |
Examples
kubectl create namespace rc-ref-del > /dev/null
trap 'kubectl delete namespace rc-ref-del --wait=false > /dev/null' EXIT
for n in a b c; do kubectl -n rc-ref-del create configmap "cfg-$n" --from-literal=x=1 > /dev/null; kubectl -n rc-ref-del label configmap "cfg-$n" batch=$([ $n = c ] && echo keep || echo old) > /dev/null; done
kubectl -n rc-ref-del delete configmap -l batch=old
kubectl -n rc-ref-del get configmap -l batch -o name
Output
configmap "cfg-a" deleted from rc-ref-del namespace configmap "cfg-b" deleted from rc-ref-del namespace configmap/cfg-c
Run this on your computer — see “Get Started” for setup.
kubectl create namespace rc-ref-del2 > /dev/null
trap 'kubectl delete namespace rc-ref-del2 --wait=false > /dev/null' EXIT
kubectl -n rc-ref-del2 create configmap gone --from-literal=x=1 > /dev/null
kubectl -n rc-ref-del2 delete configmap gone
kubectl -n rc-ref-del2 get configmap gone 2>&1 | sed 's/Error from server (NotFound): //'
Output
configmap "gone" deleted from rc-ref-del2 namespace configmaps "gone" not found
Run this on your computer — see “Get Started” for setup.
Related
kubectl apply· Create or update resources from files, directories or Kustomize folders declaratively; the standard way to deploy manifests.kubectl get· List resources in a table, or print them as YAML, JSON, JSONPath or custom columns for scripts and debugging.- kubectl Essentials · tutorial