I am writing a script to delete multiple pods across multiple namespaces. The process is to first mark all the pods to delete with a label, like kill=true, and then to delete them all.
Script as below:
kubectl label pods pod0 kill=true -n namespace0
kubectl label pods pod1 kill=true -n namespace0
kubectl label pods pod0 kill=true -n namespace1
kubectl label pods pod1 kill=true -n namespace1
......
kubectl delete pod -l kill=true --all-namespaces
When executing the last script, echo text is as below:
pod "pod0" deleted
pod "pod1" deleted
pod "pod0" deleted
pod "pod1" deleted
......
I'll insert timestamp for each line by script, as I need to know the exact time each one is killed. But the problem is I can't identify which pod is exactly killed as namespace isn't showed and there're multiple pods with the same name.
Thus my questions are as below:
- Is it possible to make kubectl show namespace in the echo text?
- If not, does kubectl guarantee the delete order in some way? Like sort by namespace, pod name?