k8s use and job management cronjob controller pod (9)

Earlier we talked about the deployment, statefulset, daemonset three kinds of controllers, each of which is their own identities
Today we learn the rest of the other two in the
job and cronjob; in fact, job and cronjob is the same function, but adding a cronjob scheduled task feature.

Summary: Job is responsible for processing tasks that only perform a task, it ensures that one or more batch jobs Pod successful conclusion. The CronJob it is time to add on Job Scheduling

Well, start practicing it


First, create a job using the countdown function

k8s use and job management cronjob controller pod (9)
cat job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: job-demo
spec:
template:
metadata:
name: job-demo
spec:
restartPolicy: Never
containers:

  • name: counter
    image: busybox
    command:
    • "bin/sh"
    • "-c"
    • "for i in 9 8 7 6 5 4 3 2 1; do echo $i; done"

Then create it

Look at the results
k8s use and job management cronjob controller pod (9)

k8s use and job management cronjob controller pod (9)


CronJob
in fact, on the basis of added time Job scheduling, we can: at a given point in time to run a task, given point in time can also be run periodically. This fact, and we in Linux crontab is very similar to the
CAT cronjob-demo.yaml
apiVersion: BATCH / v2alpha1
kind: CronJob
the Metadata:
name: Demo cronjob-
spec:
Schedule: " / 1 *"
JobTemplate:
spec:
Template:
spec:
restartPolicy: OnFailure
Containers:

  • name: hello
    image: busybox
    args:
    • "bin/sh"
    • "-c"
    • "for i in 9 8 7 6 5 4 3 2 1; do echo $i; done"

k8s use and job management cronjob controller pod (9)
spec.schedule fields are mandatory for periods specified tasks to run
spec.jobTemplate, to specify the tasks required to run
pec.successfulJobsHistoryLimit and .spec.failedJobsHistoryLimit, represent historical limitations, it is an optional field. They specify how many fail to complete and can be reserved Job, the default is no limit


kubectl create -f cronjob-demo.yaml
or used to create a CronJob RUN kubectl
kubectl Hello --schedule RUN = " /. 1 *" = --restart OnFailure --image busybox = - / bin / SH -C "DATE; echo Hello from the Kubernetes cluster "

k8s use and job management cronjob controller pod (9)
k8s use and job management cronjob controller pod (9)
Go here regularly been created, and preserved

Therefore, it deleted
k8s use and job management cronjob controller pod (9)


cronjob job and actually use it every time relative to the other in the third, much less here just show you understand just fine,
K8S five kinds of control mode now complete, and start a new learning behind,
welcome to the private letter message

Guess you like

Origin blog.51cto.com/xiaorenwutest/2483192