Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete more than one pod at a time?

Tags:

kubernetes

How can I delete more than couple of pods at a time?

The commands I run:

kubectl delete pod pod1
kubectl delete pod pod2
kubectl delete pod pod3

The approach I want to use:

kubectl delete pod pod1 pod2 pod3

Any commands or style that can help me do this? Thanks!

like image 570
cosmos-1905-14 Avatar asked Dec 21 '25 19:12

cosmos-1905-14


2 Answers

The approach that you say that you want:

kubectl delete pod pod1 pod2 pod3

actually works. Go ahead and use it if you want.

In Kubernetes it is more common to operate on subsets that share common labels, e.g:

kubectl delete pod -l app=myapp

and this command will delete all pods with the label app: myapp.

like image 172
Jonas Avatar answered Dec 24 '25 11:12

Jonas


You can use labels.

First label every pod with a common label:

apiVersion: v1
kind: Pod
metadata:
  name: myapp
  labels:
    app: myapp
    env: foo

Then delete them selecting the label:

kubectl delete pod -l env=foo

Documentation

like image 35
Marco Caberletti Avatar answered Dec 24 '25 09:12

Marco Caberletti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!