kubectl-delete
Delete Kubernetes resources
TLDR
Delete a specific pod
Delete a specific deployment
Delete a specific node
Delete all pods in a specified namespace
Delete all deployments and services in a specified namespace
Delete all nodes
Delete resources defined in a YAML manifest
SYNOPSIS
kubectl delete (-f FILENAME | TYPE [NAME_PREFIX] | TYPE/NAME | -l label_selector | -all) [options]
PARAMETERS
-f, --filename
Filename, directory, or URL to files identifying resources to delete.
-k, --kustomize
Process directory with Kustomize before deletion.
-l, --selector
Selector (label query) to filter resources.
--all
Select all resources in the namespace of the specified type.
-R, --recursive
Recursively delete all resources under a namespace.
--cascade
Deletion strategy: 'background' (default), 'orphan', or 'foreground'.
--grace-period
Period of time in seconds given to the resource to terminate gracefully.
--timeout
Maximum time to wait for deletion completion.
-n, --namespace
Namespace for the deletion.
--field-selector
Selector based on resource fields.
DESCRIPTION
The kubectl delete command removes one or more Kubernetes resources, such as pods, services, deployments, or namespaces, from a cluster. It supports deletion by resource name, label selector, file input, or all resources of a type. This is a core operation for managing cluster state, allowing users to clean up resources after use or correct misconfigurations.
Resources can be specified directly (e.g., kubectl delete pod mypod), via YAML/JSON files (-f file.yaml), or by labels (-l app=myapp). By default, it cascades deletion to dependent objects like ReplicaSets for Deployments. Use --cascade=orphan to detach instead. Graceful shutdown is supported with --grace-period and --timeout.
This command is essential for CI/CD pipelines, testing environments, and production maintenance, ensuring resources don't linger and consume cluster capacity. Always verify with kubectl get before deletion to avoid accidents. Deleted resources are permanently gone unless protected by finalizers or admission controllers.
CAVEATS
Deletion is irreversible; use kubectl get first. Finalizers may block deletion. Protected resources require manual removal.
EXAMPLES
kubectl delete pod mypod
kubectl delete -f deployment.yaml
kubectl delete deployment,replicaset -l app=myapp
kubectl delete ns myns --cascade=orphan
DRY RUN
Use --dry-run=client or server to preview deletions without applying.
HISTORY
Introduced with kubectl v1.0 in 2014 as part of Kubernetes. Evolved with cascade options in v1.5 (2017) for better dependency handling. Maintained by CNCF Kubernetes project.


