kubectl delete pods by name pattern, wildcard or label
Codemia Knowledge Hub ·
kubectl delete pod does not accept a wildcard directly. Either list pod names, filter them with grep, and pass the result to kubectl delete pod, or, better, delete by label with kubectl delete pods -l <label>.
A Pod is the smallest deployable unit in Kubernetes. It can hold one or more tightly coupled containers, storage resources, a unique network IP, and options for how the containers run. Common reasons to delete pods are freeing cluster resources, removing older pods during an update, and clearing faulty pods while troubleshooting.
Delete pods whose names match a pattern
To delete all pods whose names start with "frontend-", filter the names with grep:
How it works:
- Retrieve pod names:
kubectl get pods -o jsonpath='{.items[*].metadata.name}'lists all pod names. - Format output:
tr ' ' '\n'turns the space-separated output into one name per line. - Pattern matching:
grep '^frontend-'keeps names that start with "frontend-". - Delete pods: the filtered names are passed to
kubectl delete pod.
Delete pods by label
Labels are key/value pairs attached to objects such as pods, used to identify and organize resources. If all your frontend pods carry tier=frontend:
The -l flag specifies the label selector. This is quick and does not require parsing pod names.
Limit deletion to a namespace
Namespaces partition resources into separate sections of a cluster. Combine a namespace with a label selector:
-n mynamespace restricts the deletion to "mynamespace", and -l app=myapp selects the pods inside it.
Before you delete
- Pods owned by a Deployment come back: Kubernetes recreates pods that a Deployment manages. To scale down, adjust the replica count instead.
- Graceful termination: Kubernetes terminates pods gracefully by default. Force deletion with
--forceand--grace-period=0if necessary. - Dry run: append
--dry-run=clientto preview which pods would be deleted without removing them.
| Feature | Description |
| Bash Wildcard | Use grep with regex for pattern matching pod names easily. |
| Label-based Deletion | Use labels attached to pods for more precise and readable deletion. |
| Namespace Scope | Restrict deletion to specific namespaces with -n. |
| Graceful Termination | By default, pods are gracefully terminated unless forced. |
| Dry Run | Test the deletion command with --dry-run=client. |
Related reading
- Kubernetes pod distribution amongst nodes
- Kubernetes pod distribution amongst nodes with preferred mode
- Kubernetes pod events showing as none
- Kubernetes Pod fails with CrashLoopBackOff
- Kubernetes pod gets recreated when deleted
- Kubernetes pod not READY
- Kubernetes pod pending when a new volume is attached EKS
- Kubernetes Pod reporting more memory usage than actual process consumption
System design interview problems on this topic
- Design a Container Orchestration System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design a Task Scheduler: solution and walkthrough
- Design a GPU Cluster Scheduler for ML Training: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.