问题原文
原帖链接 · Max0999 · CC BY-SA 4.0
Upon push I want to create a single kaniko build job, it currently works but after the job is finished it shows:
kaniko-5jbhf 0/1 Completed 0 9m13s
Yet when I run the following it just pauses indefinitely:
kubectl wait --timeout=-1s --for=condition=Completed pod/kaniko
My question can be summarized in 2 parts: 1). How can I wait for a pod/job to finish? 2). How can I remove the job after it has finished?
I have tried ttlSecondsAfterFinished but enabling feature gates in the cluster is problematic and there is no example of how to do it.
已采纳解答
原帖链接 · yyyyahir · CC BY-SA 4.0
For wait to evaluate the state of a resource, you need to correctly identify it. For the second snippet, you need to provide the pod id instead of the job name: kubectl wait --timeout=-1s --for=condition=Completed pod/kaniko-5jbhf. However, the syntax seems correct for calling the job itself as job/kaniko.
For further reference on wait.
Now, for the Job deletion, if you don't want to use the feature gates, I think you can either access the API programmatically to locate and delete finished Jobs or make them dependant on a parent object that deletes them in cascade. For Jobs specifically, there's only CronJobs. The downside is that CronJobs are meant to be time-scheduled objects, this means that you need to start designing on a time-based object.
Consider that by design, Jobs are meant to stay after the completion to preserve data related to what happened while they're processing data. Also, from v1.12, they're also designed to delete themselves, meaning that enabling these feature gates is probably the most straightforward way to achieve what you want.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
