简体   繁体   English

通过昂首阔步运行容器部署执行后如何更新作业的kubernetes作业状态?

[英]How to update kubernetes job status of a job after being executed through swagger running a container deployment?

i have deployed my front end application through a deployment.yaml file using minikube having swagger-ui . 我走过了我的部署前端应用deployment.yaml文件使用minikube有swagger-ui This application simply takes in json queries and starts jobs on minikube which runs and terminates relevant containers. 该应用程序仅接受json查询并在minikube上启动作业,该作业可运行并终止相关容器。 currently i have built 1 docker image on my minikube cluster which starts downloading satellite images after the job is started. 目前,我在minikube集群上构建了1个docker映像,该映像在作业开始后开始下载卫星映像。 Now whenever i pass a json query to swagger-ui, it gives me the following response where the job status is PENDING : 现在,每当我向swagger-ui传递一个json查询时,它都会给我以下响应,其中作业状态为PENDING

{
  "workflowId": "2a94d0e3-7245-47e4-a9ce-821efce42eb8",
  "workflowName": "monitoring1",
  "status": "PENDING",
  "submittedAt": "2019-08-29T08:22:59.599469Z",
  "completedAt": null,
  "jobs": [

Job watcher 求职者

var jobStatus = JobStatus.PENDING
        when (action) {
            Watcher.Action.ADDED -> {
                if (job.status.startTime != null && job.status.active >= 0) {
                    jobStatus = JobStatus.RUNNING
                }
            }
            Watcher.Action.MODIFIED -> {
                if (job.status.completionTime != null && job.status.succeeded >= 0) {
                    jobStatus = JobStatus.COMPLETED
                } else if (job.status.failed != null) {
                    jobStatus = JobStatus.ERROR
                }
            }
            Watcher.Action.DELETED -> {
                log.info("DELETED")
            }
            Watcher.Action.ERROR -> {
                jobStatus = JobStatus.ERROR
            }
        }

on the minikuber side, the job starts and terminates after some time but on the side of swagger, the status of job never changes. 在minikuber一侧,作业会在一段时间后开始和终止,但是在摇摇欲坠的一侧,作业的状态永远不会改变。 However, when i try to run a GET query to list all jobs, there i see the completed job. 但是,当我尝试运行GET查询以列出所有作业时,我看到了完成的作业。 My question is how can i update status or notify the user once the job completes? 我的问题是工作完成后如何更新状态或通知用户? .

It might be how the question is worded, but after starting a job, is expected to get a PENDING status as the immediate response, as the job hasn't finished yet. 问题的措辞可能是这样,但是开始工作后,由于工作尚未完成,因此有望立即获得“ PENDING状态作为立即响应。 Furthermore, it looks like you're using GET to query the status of the job afterwards, which will also result in the expected behavior. 此外,看起来您之后正在使用GET查询作业的状态,这也将导致预期的行为。

Now, Swagger has support for long polling via callbacks and the Kubernetes API has read support for the verb WATCH : 现在,Swagger支持通过回调进行长时间轮询 ,而Kubernetes API已读取对动词WATCH支持

Watch will stream results for an object(s) as it is updated. 监视将在更新对象时流式传输对象的结果。 Similar to a callback, watch is used to respond to resource changes. 类似于回调,watch用于响应资源更改。

This feature also extends to your specific object Job . 此功能还扩展到您的特定对象Job

Enabling callbacks and listening to the API via watch will get you the same result as running: 启用回调并通过watch监听API,将获得与运行相同的结果:

$ kubectl get job example-job --watch -o json

So any changes to the object will be reflected as they happen, returning a JSON result that you can use later to feed your client. 因此,对对象的任何更改都会在发生时反映出来,并返回一个JSON结果,您以后可以使用它来提供给客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何控制 kubernetes 上 Job 内运行的容器数量 - How to control numbers of container running inside Job on kubernetes 如何更新Google Container Engine上的Kubernetes部署? - How to update a Kubernetes deployment on Google Container Engine? 如何将 kubernetes/openshift 机密复制到初始化容器作业的卷中? - How to copy kubernetes/openshift secrets into a volume for init container job? 通过Jenkins作业从在kubernetes pod中运行的docker容器中运行bash脚本 - Run a bash script from a docker container running in kubernetes pod via Jenkins job 如何通过 jenkins 作业在 docker 中创建 httpd 容器? - How to create a httpd container in docker through jenkins job? 如何从kubernetes作业的yml中覆盖Dockerfile的入口点`/ bin / sh`? - How to override Dockerfile's entrypoint `/bin/sh` from kubernetes job's deployment yml? 工作后运行另一个工件 - Running another artifact after a job cron作业没有在ubuntu上的docker容器内运行 - cron job not running inside docker container on ubuntu Airflow 在 Docker 中运行其他容器的作业 - Airflow Running Other Container's Job in Docker Logrotation未通过cron作业在docker容器中运行 - Logrotation is not running in docker container via cron job
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM