<p>I am trying to schedule Jobs in Kubernetes.</p>

<p><a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/</a></p>

<p>The job can be created using the below command.</p>

<pre><code>$ kubectl create -f ./cronjob.yaml
cronjob "hello" created
</code></pre>

<p>Is there any REST API using which the Job can be created from a Java client?</p>

<p>Thanks</p>

<p>The respective REST endpoint is described in <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#cronjob-v1beta1-batch" rel="nofollow noreferrer">the official API reference</a>. You will find the <code>CronJob</code> resource in the <code>batch/v1beta1</code> API group. To create a new <code>CronJob</code> resource, you'll need a POST call to the <code>/apis/batch/v1beta1/namespaces/{namespace}/cronjobs</code> URL.</p>

<p>A respective HTTP request might look something like this:</p>

<pre><code>POST /apis/batch/v1beta1/namespaces/default/cronjobs HTTP/1.1
Content-Type: application/json
Content-Length: ...
Authorization: ...
[other headers]

{
  "metadata": {
    "name": "some-cron"
  },
  "spec": {
    ...
  }
}
</code></pre>

<p>There are also older versions of the same resource, for example in the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#cronjob-v2alpha1-batch" rel="nofollow noreferrer"><code>batch/v2alpha1</code> API group</a>. As a rule of thumb, I'd recommend using the newest API version available to you. Especially, do not rely on alpha APIs in production; they tend to deprecate pretty quickly between releases.</p>

<p>To create a <code>batch/v1beta1</code> CronJob using the Java client, have a look at the <a href="https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/BatchV1beta1Api.md#createNamespacedCronJob" rel="nofollow noreferrer"><code>createNamespacedCronJob</code> method</a> of the <code>io.kubernetes.client.openapi.apis.BatchV1beta1Api</code> class.</p>
