kubernetes 使用包含子字符串的kubectl删除pod

rdrgkggo  于 2022-11-21  发布在  Kubernetes
关注(0)|答案(2)|浏览(134)

当我运行命令kubectl get pods | grep "apisix"时,我得到以下数据

apisix-dev-78549978b7-pvh2v                           1/1     Running             6 (4m19s ago)   8m14s
apisix-dev-dashboard-646df79bf-mwkpc                  1/1     Running             6 (4m35s ago)   8m12s
apisix-dev-etcd-0                                     1/1     Running             0               8m12s
apisix-dev-etcd-1                                     1/1     Running             0               8m11s
apisix-dev-etcd-2                                     0/1     CrashLoopBackOff    4 (24s ago)     8m11s
apisix-dev-ingress-controller-58f7887759-28cm9        1/1     Running             0               8m11s
apisix-dev-ingress-controller-6cc65c7cb5-k6dx2        0/1     Init:0/1            0               8m9s

是否有办法删除所有包含单词apisix的pod,而不是在kubectl delete命令中提及每个pod名称?

mnemlml8

mnemlml81#

您可以运行一个简单的命令:

kubectl delete pod $(kubectl get pod | grep apisix | awk '{print $1}')
g0czyy6m

g0czyy6m2#

选择(然后可能删除)一组Pod的常用方法是通过selector标签。
例如,假设存在值为apisix的正确标签app

# Find which Pods are selected (just to be sure)
kubectl get pod --selector=app=apisix

# Delete them (probably with --dry-run=client, if still unsure about what is selected)
kubectl delete pod --selector=app=apisix

相关问题