此文档中的信息可能已过时
此文档的更新日期比原文晚,因此其中的信息可能已过时。如果能阅读英文,请查看英文版本以获取最新信息: CronJob
CronJob
apiVersion: batch/v1
import "k8s.io/api/batch/v1"
CronJob
CronJob 代表单个定时作业(Cron Job)的配置。
- apiVersion: batch/v1 
- kind: CronJob 
- metadata (ObjectMeta) - 标准的对象元数据。更多信息: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 
- spec (CronJobSpec) - 定时作业的预期行为的规约,包括排期表(Schedule)。更多信息: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status 
- status (CronJobStatus) - 定时作业的当前状态。更多信息: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status 
CronJobSpec
CronJobSpec 描述了作业的执行方式和实际将运行的时间。
- jobTemplate (JobTemplateSpec),必需 - 指定执行 CronJob 时将创建的作业。 - JobTemplateSpec 描述了从模板创建作业时应具有的数据 - jobTemplate.metadata (ObjectMeta) - 从此模板创建的作业的标准对象元数据。更多信息: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 
 - jobTemplate.spec (JobSpec) - 对作业的预期行为的规约。更多信息: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status 
 
- schedule (string),必需 - Cron 格式的排期表,请参阅 https://zh.wikipedia.org/wiki/Cron。 
- timeZone (string) - 给定时间表的时区名称,请参阅 https://en.wikipedia.org/wiki/List_of_tz_database_time_zones。 如果未指定,这将默认为 kube-controller-manager 进程的时区。 有效时区名称和时区偏移量的设置由 API 服务器在 CronJob 验证期间从系统范围的时区数据库进行加载, 在执行期间由控制器管理器从系统范围的时区数据库进行加载。 如果找不到系统范围的时区数据库,则转而使用该数据库的捆绑版本。 如果时区名称在 CronJob 的生命周期内或由于主机配置更改而变得无效,该控制器将停止创建新的 Job, 并将创建一个原因为 UnknownTimeZone 的系统事件。更多信息,请参阅 https://kubernetes.io/zh-cn/docs/concepts/workloads/controllers/cron-jobs/#time-zones。 
- concurrencyPolicy (string) - 指定如何处理作业的并发执行。有效值为: - "Allow" (默认):允许 CronJobs 并发运行;
- "Forbid":禁止并发运行,如果上一次运行尚未完成则跳过下一次运行;
- "Replace":取消当前正在运行的作业并将其替换为新作业。
 
- startingDeadlineSeconds (int64) - 可选字段。当作业因为某种原因错过预定时间时,设定作业的启动截止时间(秒)。错过排期的作业将被视为失败的作业。 
- suspend (boolean) - 这个标志告诉控制器暂停后续的执行,它不适用于已经开始的执行。默认为 false。 
- successfulJobsHistoryLimit (int32) - 要保留的成功完成作业数。值必须是非负整数。默认值为 3。 
- failedJobsHistoryLimit (int32) - 要保留的以失败状态结束的作业个数。值必须是非负整数。默认值为 1。 
CronJobStatus
CronJobStatus 表示某个定时作业的当前状态。
- active ([]ObjectReference) - Atomic: 将在合并过程中被替换 - 指向当前正在运行的作业的指针列表。 
- lastScheduleTime (Time) - 上次成功调度作业的时间信息。 - Time 是对 time.Time 的封装,它支持对 YAML 和 JSON 的正确编排。为 time 包提供的许多工厂方法模式提供了包装器。 
- lastSuccessfulTime (Time) - 上次成功完成作业的时间信息。 - Time 是对 time.Time 的封装,它支持对 YAML 和 JSON 的正确编排。为 time 包提供的许多工厂方法模式提供了包装器。 
CronJobList
CronJobList 是定时作业的集合。
- apiVersion: batch/v1 
- kind: CronJobList 
- metadata (ListMeta) - 标准列表元数据。更多信息: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 
- items ([]CronJob), required - items 是 CronJob 的列表。 
操作
get 查看指定的 CronJob
HTTP 请求
GET /apis/batch/v1/namespaces/{namespace}/cronjobs/{name}
参数
响应
200 (CronJob): OK
401: Unauthorized
get 查看指定 CronJob 的状态
HTTP 请求
GET /apis/batch/v1/namespaces/{namespace}/cronjobs/{name}/status
参数
响应
200 (CronJob): OK
401: Unauthorized
list 查看或监视 CronJob 类别的对象
HTTP 请求
GET /apis/batch/v1/namespaces/{namespace}/cronjobs
参数
- namespace (路径参数): string,必需 
- allowWatchBookmarks (查询参数): boolean 
- continue (查询参数): string 
- fieldSelector (查询参数): string 
- labelSelector (查询参数): string 
- limit (查询参数): integer 
- pretty (查询参数): string 
- resourceVersion (查询参数): string 
- resourceVersionMatch (查询参数): string 
- sendInitialEvents (查询参数): boolean 
- timeoutSeconds (查询参数): integer 
- watch (查询参数): boolean 
响应
200 (CronJobList): OK
401: Unauthorized
list 查看或监视 CronJob 类型的对象
HTTP 请求
GET /apis/batch/v1/cronjobs
参数
- allowWatchBookmarks (in query): boolean 
- continue (in query): string 
- fieldSelector (in query): string 
- labelSelector (in query): string 
- limit (in query): integer 
- pretty (in query): string 
- resourceVersion (in query): string 
- resourceVersionMatch (查询参数): string 
- sendInitialEvents (查询参数): boolean 
- timeoutSeconds (in query): integer 
- watch (in query): boolean 
响应
200 (CronJobList): OK
401: Unauthorized
create 创建一个 CronJob
HTTP 请求
POST /apis/batch/v1/namespaces/{namespace}/cronjobs
参数
- namespace (路径参数): string,必需 
- body: CronJob,必需
- dryRun (查询参数): string 
- fieldManager (查询参数): string 
- fieldValidation (查询参数): string 
- pretty (查询参数): string 
响应
200 (CronJob): OK
201 (CronJob): Created
202 (CronJob): Accepted
401: Unauthorized
update 替换指定的 CronJob
HTTP 请求
PUT /apis/batch/v1/namespaces/{namespace}/cronjobs/{name}
参数
- name (路径参数): string,必需 - CronJob 的名称 
- namespace (路径参数): string,必需 
- body: CronJob,必需
- dryRun (查询参数): string 
- fieldManager (查询参数): string 
- fieldValidation (查询参数): string 
- pretty (查询参数): string 
响应
200 (CronJob): OK
201 (CronJob): Created
401: Unauthorized
update 替换指定 CronJob 的状态
HTTP 请求
PUT /apis/batch/v1/namespaces/{namespace}/cronjobs/{name}/status
参数
- name (路径参数): string,必需 - CronJob 的名称 
- namespace (路径参数): string,必需 
- body: CronJob,必需
- dryRun (查询参数): string 
- fieldManager (查询参数): string 
- fieldValidation (查询参数): string 
- pretty (查询参数): string 
响应
200 (CronJob): OK
201 (CronJob): Created
401: Unauthorized
patch 部分更新指定的 CronJob
HTTP 请求
PATCH /apis/batch/v1/namespaces/{namespace}/cronjobs/{name}
参数
- name (路径参数): string,必需 - CronJob 的名称 
- namespace (路径参数): string,必需 
- body: Patch,必需
- dryRun (查询参数): string 
- fieldManager (查询参数): string 
- fieldValidation (查询参数): string 
- force (查询参数): boolean 
- pretty (查询参数): string 
响应
200 (CronJob): OK
201 (CronJob): Created
401: Unauthorized
patch 部分更新指定 CronJob 的状态
HTTP 请求
PATCH /apis/batch/v1/namespaces/{namespace}/cronjobs/{name}/status
参数
- name (路径参数): string,必需 - CronJob 的名称 
- namespace (路径参数): string,必需 
- body: Patch,必需
- dryRun (参数参数): string 
- fieldManager (参数参数): string 
- fieldValidation (参数参数): string 
- force (参数参数): boolean 
- pretty (参数参数): string 
响应
200 (CronJob): OK
201 (CronJob): Created
401: Unauthorized
delete 删除一个 CronJob
HTTP 请求
DELETE /apis/batch/v1/namespaces/{namespace}/cronjobs/{name}
参数
- name (路径参数): string,必需 - CronJob 的名称 
- namespace (路径参数): string,必需 
- body: DeleteOptions
- dryRun (查询参数): string 
- gracePeriodSeconds (查询参数): integer 
- ignoreStoreReadErrorWithClusterBreakingPotential (查询参数): boolean 
- pretty (查询参数): string 
- propagationPolicy (查询参数): string 
响应
200 (Status): OK
202 (Status): Accepted
401: Unauthorized
deletecollection 删除一组 CronJob
HTTP 请求
DELETE /apis/batch/v1/namespaces/{namespace}/cronjobs
参数
- namespace (路径参数): string,必需 
- body: DeleteOptions
- continue (查询参数): string 
- dryRun (查询参数): string 
- fieldSelector (查询参数): string 
- gracePeriodSeconds (查询参数): integer 
- ignoreStoreReadErrorWithClusterBreakingPotential (查询参数): boolean 
- labelSelector (查询参数): string 
- limit (查询参数): integer 
- pretty (查询参数): string 
- propagationPolicy (查询参数): string 
- resourceVersion (查询参数): string 
- resourceVersionMatch (查询参数): string 
- sendInitialEvents (查询参数): boolean 
- timeoutSeconds (查询参数): integer 
响应
200 (Status): OK
401: Unauthorized