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 | -l label)] | TYPE/NAME) [flags]
PARAMETERS
-f, --filename string
Path to a file that contains the resource to delete. Can be specified multiple times.
TYPE
The Kubernetes resource type to delete (e.g., pod, service, deployment).
NAME
The name of the resource to delete.
-l, --selector string
Selector (label query) to filter on, supports '=', '==', and '!='.(e.g., -l key1=value1,key2=value2). Matching objects will be deleted.
--all
Select all resources in the namespace.
--cascade string
Must be 'background', 'orphan', or 'foreground'. Selects the deletion cascading strategy for the dependents. Defaults to foreground. Background: Orphans the dependents. Foreground: A cascading policy that deletes all dependents. Orphan: Deletes the selected resources but leaves the dependents.
--grace-period int
Period of time in seconds given to the resource to terminate gracefully. Value must be non-negative integer. The value zero indicates delete immediately. If a value is unspecified, the default value will be used.
--ignore-not-found
Treat 'resource not found' as a successful deletion.
--namespace string
If present, the namespace scope for this CLI request.
--now
If true, resources are signaled for immediate shutdown (same as --grace-period=0).
--recursive
Process all directories found in the path when using -f, --filename. Recursive processing is useful when you want to manage related resources organized within the same directory.
--wait
If true, wait until the resource is deleted.
DESCRIPTION
The kubectl delete command is used to delete Kubernetes resources from a cluster.
It offers flexibility in specifying resources for deletion, allowing users to target resources by name, file, label selector, or all resources of a specific type.
Deleting resources removes them from the Kubernetes system, freeing up resources and effectively removing the corresponding application component.
Care should be exercised when using this command to avoid unintentionally disrupting applications or deleting critical system resources.
Common uses include deleting deployments, services, pods, and other Kubernetes objects. Deletion is performed by contacting the Kubernetes API server, which then orchestrates the removal of the specified resources based on their defined controllers and deletion policies.
The command supports various flags to control deletion behavior, such as graceful deletion periods and cascading deletion of dependent resources.
EXAMPLES
kubectl delete pod my-pod
Deletes a pod named 'my-pod'.
kubectl delete deployment my-dep
Deletes a deployment named 'my-dep'.
kubectl delete -f my-config.yaml
Deletes the resources defined in the file 'my-config.yaml'.
kubectl delete pod -l status=pending
Deletes all pods with the label 'status=pending'.
kubectl delete namespace my-namespace
Deletes the namespace named 'my-namespace' and all resources within it.
SEE ALSO
kubectl(1), kubectl-apply(1), kubectl-create(1), kubectl-get(1)