CronJobâ , . CronJobâ Jobâ (, - , ) , , Job , , , . Jobâ Kubernetes (workloads).
Kubernetes : ReplicaSets, DaemonSets, Deployments StatefulSets. . , . (node), , .
, , ? , , . (backup, ) - , . . , , (exit status), , .
Jobâ Kubernetes
Jobâ Kubernetes:
: // . .
/ : , /, .
Jobâ Kubernetes , . , Job . Job , .
Kubernetes Job
Jobâ Kubernetes, Kubernetes, (definition file). , job.yaml. :
apiVersion: batch/v1
kind: Job
metadata:
name: hello-world
spec:
template:
metadata:
name: hello-world
spec:
containers:
- name: hello-world
image: busybox
command: ["echo", "Running a hello-world job"]
restartPolicy: OnFailure
Kubernetes, Kubernetes kubectl. :
$ kubectl apply -f job.yaml job.batch/hello-world created
, :
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-world-mstmc 0/1 ContainerCreating 0 1s
jobâ kubectl:
kubectl get jobs hello-world-mstmc
NAME COMPLETIONS DURATION AGE
hello-world-mstmc 1/1 21s 27s
:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-world-mstmc 0/1 Completed 0 25s
, . Completed, job . Job, , :) - echo âRunning a hello-world jobâ .
, , job , :
kubectl logs -f hello-world-mstmc Running a hello-world job
, , .. âRunning a hello-world jobâ. Job .
CronJob
, cronjob . , job cronjobâ.
, , cronjob , .
kubectl create job --from=cronjob/kubernetes-cron-job manual-cron-job
--from=cronjob/kubernetes-cron-job
cronjobâ job manual-cron-job
Jobâ Kubernetes (Cleanup)
Job Kubernetes , Job, . . , - , Job .
Job kubectl :
kubectl delete jobs job_name
Job . Kubernetes, Job, , cascade=false
. :
kubectl delete jobs job_name cascade=false
, jobâ/cronjobâ kubernetes . .
1. failedJobHistoryLimit successfulJobsHistoryLimit: jobâ . , , jobâ. ,
failedJobHistoryLimit: 5
successfulJobsHistoryLimit: 10
2. backoffLimit: .
RestartPolicy Jobâ Kubernetes
restartPolic
y ( ) âalwaysâ (). Job . , restartPolicy
âNeverâ () âOnFailureâ ( ).
Jobâ Kubernetes
Jobâ , , , Jobâ Kubernetes spec.activeDeadlineSeconds
. Jobâ .
, .spec.backoffLimit
, .. Job , . .
Job backoff limit
, deadline
:
apiVersion: batch/v1
kind: Job
metadata:
name: data-consumer
spec:
backoffLimit: 5
activeDeadlineSeconds: 20
template:
spec:
containers:
- name: consumer
image: busybox
command: ["/bin/sh", "-c"]
args: ["echo 'Consuming data'; sleep 1; exit 1"]
restartPolicy: OnFailure
Jobâ
, , Job, ârun-onceâ. .
Jobâ
, , . jobâ, , . Jobâ Kubernetes, .spec.completions - ( , ). Job (completions). Job , . . , :
apiVersion: batch/v1
kind: Job
metadata:
name: data-consumer
spec:
completions: 5
template:
metadata:
name: data-consumer
spec:
containers:
- name: data-consumer
image: busybox
command: ["/bin/sh","-c"]
args: ["echo 'consuming a message from queue'; sleep 5"]
restartPolicy: OnFailure
completions 5.
Jobâ (Work Queue)
jobâ, , , . , data science .
, :
apiVersion: batch/v1
kind: Job
metadata:
name: data-consumer
spec:
parallelism: 5
template:
metadata:
name: data-consumer
spec:
containers:
- name: data-consumer
image: busybox
command: ["/bin/sh","-c"]
args: ["echo 'consuming a message from queue'; sleep $(shuf -i 5-10 -n 1)"]
restartPolicy: OnFailure
.spec.completions
. parallelism
. completions
parallelism
(5). Job :
5 , Job. , , Job . , Job .
Kubernetes Job 5 . , , . , (, AWS SQS). , Job , . :
.
.
, , ( 5 10), . , , , API.
CronJobâ
Cronjob job (schedule). «», jobâ . , . , jobâ .
startingDeadlineSeconds
( ) concurrencyPolicy
Allow, job .
CronJobâ CronJob , . 100, job .
Cannot determine if job needs to be started. Too many missed start time (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.
, startingDeadlineSeconds
(.. nil
), jobâ startingDeadlineSeconds
, . , startDeadlineSeconds
200
, , jobâ 200 .
CronJob , . , concurrencyPolicy
Forbid
CronJob , .
, , CronJob Job 08:30:00
, startingDeadlineSeconds
. CronJob 08:29:00
10:21:00
, job , jobâ 100.
, , CronJob Job 08:30:00
startingDeadlineSeconds
200 . CronJob , ( 08:29:00
10:21:00
), Job 10:22:00. , , 200 (. . 3 ), , .
CronJob Jobâ, , Job, , .
TL;DR (Too Long; Didnât Read)
Jobâ Kubernetes , , , .
Jobâ Kubernetes ; Job .
restartPolicy
Job «Never» «OnFailure»
Jobâ completions parallelism , . Jobâ , , .
Jobâ ,
.spec.backoffLimit
. .
jobâ, .
spec.activeDeadlineSeconds
.backoffLimit
. , Job , .
Jobâ .
ttlSecondsAfterFinished
, alpha.
" Kubernetes". - : " NoSQL k8s ( Apache Cassandra)"