本文章向大家介绍kubernetes批量删除pod,主要包括kubernetes批量删除pod使用实例、应用技巧、基本知识点总结和需要注意事项。
查看要删除的pod
[root@master ~]# kubectl get pods -n dev -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-5bdb994596-2nzlz 1/1 Running 1 (2d19h ago) 3d 10.244.1.17 node1 <none> <none>
nginx-5bdb994596-p5pfq 1/1 Running 1 (2d19h ago) 3d 10.244.1.16 node1 <none> <none>
nginx-5bdb994596-vw9m7 1/1 Running 1 (2d19h ago) 3d 10.244.2.23 node2 <none> <none>
pod-base 2/2 Running 2 (2d19h ago) 2d23h 10.244.2.22 node2 <none> <none>
pod-hook-exec 1/1 Running 1 (2d19h ago) 2d23h 10.244.1.18 node1 <none> <none>
pod-initcontainer 1/1 Running 0 4h11m 10.244.2.25 node2 <none> <none>
pod-liveness-exec 0/1 CrashLoopBackOff 85 (16s ago) 4h5m 10.244.1.20 node1 <none> <none>
pod-liveness-httpget 0/1 CrashLoopBackOff 39 (4m54s ago) 110m 10.244.1.21 node1 <none> <none>
pod-liveness-tcpsocket 0/1 CrashLoopBackOff 83 (4m2s ago) 4h4m 10.244.2.26 node2 <none> <none>
pod-nodeaffinity-preferred 1/1 Running 0 31m 10.244.2.28 node2 <none> <none>
pod-nodeaffinity-required 1/1 Running 0 32m 10.244.1.24 node1 <none> <none>
pod-nodeselector 0/1 Pending 0 36m <none> <none> <none> <none>
pod-podaffinity-required 1/1 Running 0 23m 10.244.1.26 node1 <none> <none>
pod-podaffinity-target 1/1 Running 0 27m 10.244.1.25 node1 <none> <none>
pod-podantiaffinity-required 1/1 Running 0 20m 10.244.2.29 node2 <none> <none>
pod-restartpolicy 0/1 Completed 0 42m 10.244.2.27 node2 <none> <none>
taint1 1/1 Running 0 6s 10.244.2.30 node2 <none> <none>
获取Pod的名字,这边grep后面是/
,是删除所有的容器,可以根据自己需要,过滤特定的Pods
[root@master ~]# kubectl get pods -n dev -o wide |grep /|awk '{print $1}'
pod-base
pod-hook-exec
pod-initcontainer
pod-liveness-exec
pod-liveness-httpget
pod-liveness-tcpsocket
pod-nodeaffinity-preferred
pod-nodeaffinity-required
pod-nodeselector
pod-podaffinity-required
pod-podaffinity-target
pod-podantiaffinity-required
pod-restartpolicy
taint1
删除Pod
[root@master ~]# kubectl get pods -n dev -o wide |grep /|awk '{print $1}' |xargs kubectl delete pod -n dev
pod "pod-base" deleted
pod "pod-hook-exec" deleted
pod "pod-initcontainer" deleted
pod "pod-liveness-exec" deleted
pod "pod-liveness-httpget" deleted
pod "pod-liveness-tcpsocket" deleted
pod "pod-nodeaffinity-preferred" deleted
pod "pod-nodeaffinity-required" deleted
pod "pod-nodeselector" deleted
pod "pod-podaffinity-required" deleted
pod "pod-podaffinity-target" deleted
pod "pod-podantiaffinity-required" deleted
pod "pod-restartpolicy" deleted
pod "taint1" deleted
查看Pod
[root@master ~]# kubectl get pods -n dev
No resources found in dev namespace.