Scheduling a build using Kubernetes

Viewed 99

The doc https://docs.openshift.com/container-platform/3.9/dev_guide/cron_jobs.html provides details of creating a cron job.

To start a scheduled task that executes a build every 10 mins I use the command:

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:

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 ?

2 Answers

You are trying to override the image CMD/ARG with the 161/my-app command (which seems not to be valid).

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.

If you want to use the default CMD/ARG built in the container image, just omit the --command flag and its value.

First of all, It is not easy to find a full docs for the oc run, so let's discuss with the source code


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.

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

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.

There is always a CMD defined in a Docker image, so we have to decide whether to use the default CMD:

If the default CMD would be used and want to modify the args: Check this example

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

If a new CMD and args would be used: Check this Example

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
  2. for the openshift-build part, you may reference here
Related