Kubernetes: How to delete PODs based on age/creation time

后端 未结 3 2084
执念已碎
执念已碎 2020-12-30 07:51

Is it possible to delete POD in kubernetes based on creation time or age?

Example : I would like to delete all PODs which are older than 1 day. These PODs are orpha

3条回答
  •  清歌不尽
    2020-12-30 08:18

    We could this with only awk by doing a regex [0-9]+d directly on the AGE ($5, 5th column) column and then printing the corresponding NAME ($1, first column) column

    kubectl delete pod $(kubectl get pod | awk 'match($5,/[0-9]+d/) {print $1}')
    

    Test first to see what's matching:

    kubectl get pod | awk 'match($5,/[0-9]+d/) {print $0}'
    

    $0 means all columns

提交回复
热议问题