[英]Kubernetes - Job scheduling API
I am trying to schedule Jobs in Kubernetes.我正在尝试在 Kubernetes 中安排作业。
https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/ https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/
The job can be created using the below command.可以使用以下命令创建作业。
$ kubectl create -f ./cronjob.yaml
cronjob "hello" created
Is there any REST API using which the Job can be created from a Java client?是否有任何可以从 Java 客户端创建作业的 REST API?
Thanks谢谢
The respective REST endpoint is described in the official API reference . 官方 API 参考中描述了相应的 REST 端点。 You will find the
CronJob
resource in the batch/v1beta1
API group.您将在
batch/v1beta1
API 组中找到CronJob
资源。 To create a new CronJob
resource, you'll need a POST call to the /apis/batch/v1beta1/namespaces/{namespace}/cronjobs
URL.要创建新的
CronJob
资源,您需要对/apis/batch/v1beta1/namespaces/{namespace}/cronjobs
URL 进行 POST 调用。
A respective HTTP request might look something like this:相应的 HTTP 请求可能如下所示:
POST /apis/batch/v1beta1/namespaces/default/cronjobs HTTP/1.1
Content-Type: application/json
Content-Length: ...
Authorization: ...
[other headers]
{
"metadata": {
"name": "some-cron"
},
"spec": {
...
}
}
There are also older versions of the same resource, for example in the batch/v2alpha1
API group .还有相同资源的旧版本,例如在
batch/v2alpha1
API group 中。 As a rule of thumb, I'd recommend using the newest API version available to you.根据经验,我建议您使用可用的最新 API 版本。 Especially, do not rely on alpha APIs in production;
特别是,不要在生产中依赖 alpha API; they tend to deprecate pretty quickly between releases.
他们往往会在发布之间很快弃用。
To create a batch/v1beta1
CronJob using the Java client, have a look at the createNamespacedCronJob
method of the io.kubernetes.client.openapi.apis.BatchV1beta1Api
class.要使用 Java 客户端创建
batch/v1beta1
CronJob,请查看io.kubernetes.client.openapi.apis.BatchV1beta1Api
类的createNamespacedCronJob
方法。
HTTP Request HTTP 请求
POST /apis/batch/v1beta1/namespaces/{namespace}/cronjobs
You can take a look here for API overview: cronjob-v1beta1-batch您可以在此处查看 API 概述: cronjob-v1beta1-batch
Add CronJob object in request Body.在请求正文中添加 CronJob 对象。
{
"apiVersion": "batch/v1beta1",
"kind": "CronJob",
"metadata": {
"name": "hello"
},
"spec": {
"schedule": "*/1 * * * *",
"jobTemplate": {
}
}
}
Check here its spec: writing-a-cron-job-spec在此处查看其规范: writing-a-cron-job-spec
Part of swagger.json swagger.json 的一部分
"post": {
"description": "create a CronJob",
"consumes": [
"*/*"
],
"produces": [
"application/json",
"application/yaml",
"application/vnd.kubernetes.protobuf"
],
"schemes": [
"https"
],
"tags": [
"batch_v1beta1"
],
"operationId": "createBatchV1beta1NamespacedCronJob",
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/io.k8s.api.batch.v1beta1.CronJob"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/io.k8s.api.batch.v1beta1.CronJob"
}
},
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/io.k8s.api.batch.v1beta1.CronJob"
}
},
"202": {
"description": "Accepted",
"schema": {
"$ref": "#/definitions/io.k8s.api.batch.v1beta1.CronJob"
}
},
"401": {
"description": "Unauthorized"
}
},
"x-kubernetes-action": "post",
"x-kubernetes-group-version-kind": {
"group": "batch",
"kind": "CronJob",
"version": "v1beta1"
}
}
See full swagger.json查看完整的swagger.json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.