简体   繁体   English

使用 Kubernetes 计划构建

[英]Scheduling a build using Kubernetes

The doc https://docs.openshift.com/container-platform/3.9/dev_guide/cron_jobs.html provides details of creating a cron job.文档https://docs.openshift.com/container-platform/3.9/dev_guide/cron_jobs.html提供了创建 cron 作业的详细信息。

To start a scheduled task that executes a build every 10 mins I use the command:要启动每 10 分钟执行一次构建的计划任务,我使用以下命令:

oc run run-build 161/my-app --image=myimage --restart=OnFailure --schedule='*/10 * * * *' 

Which returns:返回:

cronjob.batch/run-build created

But the job fails to start:但是作业无法开始:

The log of pod displays: pod的日志显示:

Error: unknown command "161/my-app" for "openshift-deploy"
Run 'openshift-deploy --help' for usage.

Have I configured the command ( oc run run-build 161/my-app --image=myimage --restart=OnFailure --schedule='*/10 * * * *' ) to start the cron job incorrectly?我是否配置了命令( oc run run-build 161/my-app --image=myimage --restart=OnFailure --schedule='*/10 * * * *' )以错误地启动 cron 作业?

You are trying to override the image CMD / ARG with the 161/my-app command (which seems not to be valid).您正在尝试使用161/my-app命令(这似乎无效)覆盖图像CMD / ARG

You should use:你应该使用:

oc run run-build --image=myimage --schedule='*/10 * * * *' \
--restart=OnFailure \
--command -- <YOUR COMMAND HERE>

Where run-build is the name of your created cronjob.其中run-build是您创建的 cronjob 的名称。

If you want to use the default CMD / ARG built in the container image, just omit the --command flag and its value.如果要使用容器镜像中内置的默认CMD / ARG ,只需省略--command标志及其值。

First of all, It is not easy to find a full docs for the oc run , so let's discuss with the source code首先, oc run的完整文档不容易找到,所以还是和源码一起讨论吧


As the cronjob.batch/run-build has been created, the build is scheduled by kubernetes, so there may be no problem for the schedule part.由于已经创建了cronjob.batch/run-build ,构建是由kubernetes调度的,所以调度部分可能没有问题。

The prolem is now why the image run failed.现在的问题是图像运行失败的原因。

we can find it from the logs, 161/my-app is recognized as an args for the command openshift-deploy which should be the CMD defined in --image=myimage我们可以从日志中找到它, 161/my-app被识别为命令openshift-deploy的参数,它应该是--image=myimage

Error: unknown command "161/my-app" for "openshift-deploy"
Run 'openshift-deploy --help' for usage.

You have to expain the 161/my-app and update the command based on it.您必须扩展161/my-app并根据它更新命令。

There is always a CMD defined in a Docker image, so we have to decide whether to use the default CMD:在 Docker 镜像中总是定义了一个 CMD,所以我们必须决定是否使用默认的 CMD:

If the default CMD would be used and want to modify the args: Check this example如果将使用默认 CMD 并想修改参数: 检查此示例

oc run nginx --image=nginx -- <arg1> <arg2> ... <argN>

If a new CMD and args would be used: Check this Example如果使用新的 CMD 和 args: 检查此示例

oc run nginx --image=nginx --command -- <cmd> <arg1> ... <argN>

I noticed two more infos in your questions, you can check here and update the question if necessary:我注意到您的问题中还有两个信息,您可以在此处查看并在必要时更新问题:

  1. for the openshift-deploy part, you may reference here对于openshift-deploy部分,您可以在此处参考
  2. for the openshift-build part, you may reference here对于openshift-build部分,您可以在此处参考

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM