监控kubernetes作业 [英] Monitoring a kubernetes job
问题描述
我有kubernetes作业,需要花费可变的时间才能完成.在4到8分钟之间.有什么方法可以让我知道什么时候完成工作,而不是在最坏的情况下等待8分钟.我有一个执行以下操作的测试用例:
I have kubernetes jobs that takes variable amount of time to complete. Between 4 to 8 minutes. Is there any way i can know when a job have completed, rather than waiting for 8 minutes assuming worst case. I have a test case that does the following:
1) Submits the kubernetes job.
2) Waits for its completion.
3) Checks whether the job has had the expected affect.
问题是,在我的Java测试中,它在kubernetes中提交了部署作业,即使该作业花费的时间少于完成的时间,我仍要等待8分钟,因为我没有办法监视作业的状态来自Java测试.
Problem is that in my java test that submits the deployment job in the kubernetes, I am waiting for 8 minutes even if the job has taken less than that to complete, as i dont have a way to monitor the status of the job from the java test.
推荐答案
<kube master>/apis/batch/v1/namespaces/default/jobs
端点列出了作业的状态.我已经解析了这个json并检索了以"deploy ..."开头的最新运行作业的名称.
endpoint lists status of the jobs. I have parsed this json and retrieved the name of the latest running job that starts with "deploy...".
那我们就可以打
<kube master>/apis/batch/v1/namespaces/default/jobs/<job name retrieved above>
并在作业成功后监视以下状态字段值
And monitor the status field value which is as below when the job succeeds
"status": {
"conditions": [
{
"type": "Complete",
"status": "True",
"lastProbeTime": "2016-09-22T13:59:03Z",
"lastTransitionTime": "2016-09-22T13:59:03Z"
}
],
"startTime": "2016-09-22T13:56:42Z",
"completionTime": "2016-09-22T13:59:03Z",
"succeeded": 1
}
因此,我们一直在轮询该端点,直到完成为止.希望这对某人有帮助.
So we keep polling this endpoint till it completes. Hope this helps someone.
这篇关于监控kubernetes作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!