kubectl list / delete all completed jobs

依然范特西╮ 提交于 2019-12-11 02:56:37

问题


I'm looking for a kubectl command to list / delete all completed jobs

I've try:

kubectl get job --field-selector status.succeeded=1

But I get:

enfield selector "status.succeeded=1": field label "status.succeeded" not supported for batchv1.Jobter code here

What are the possible fields for --fieldSelector when getting jobs ?

Is there a better way to do this ?


回答1:


What you can do to list all the succeeded jobs is first get all the jobs and then filter the output:

kubectl get job --all-namespaces | grep "succeeded"

If you want to delete all the succeded jobs you can use the following command:

kubectl delete job $(kubectl get job -o=jsonpath='{.items[?(@.status.succeeded==1)].metadata.name}')



回答2:


FWIW, the following returns all jobs that have failed:

kubectl get jobs $(kubectl get jobs -o=jsonpath='{.items[?(@.status.failed>0)].metadata.name}')

And all jobs that are still running:

kubectl get jobs $(kubectl get jobs -o=jsonpath='{.items[?(@.status.active==1)].metadata.name}')


来源:https://stackoverflow.com/questions/53539576/kubectl-list-delete-all-completed-jobs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!