Job Examples:
Apiversion:batch/v1 #job的apiVersionkind: Job #资源类型为jobmetadata: Labels: name:busybox Name: Busyboxspec: Template: metadata: name:busybox Spec: containers: -Name:busybox Image:myhub.mingyuanyun.com/library/busybox command: -sleep -" restartpolicy:never" #什么情况下重启容器, the job can only be set to never and onfailure, generally set to never
Restartpolicy:never #如果使用参数Never, the container does not succeed after it has been started creating a new container
Restartpolicy:onfailure #如果使用参数OnFailure, the container starts unsuccessfully and does not create a new container, he will always restart
Kubectl apply-f Myjob.yaml
Kubectl Get Job
Kubectl Get pod--show-all
Kubectl logs BusyBox
Kubectl delete-f Myjob.yaml
Creating a parallel job:
APIVERSION:BATCH/V1 kind:job metadata: Labels: name:busybox Name:busyboxspec:
Completions:6 #直到总共有6个pod成功执行 If you do not specify a default value of 1
Parallelism:2 #一次启动2个pod来执行job If you do not specify a default value of 1 Template: metadata: name:busybox Spec: containers: -name:busybox image:myhub.mingyuanyun.com/library/busybox command: - Sleep -"Restartpolicy:never"
Timed job:
APIVERSION:BATCH/V2ALPHA1 #当前CronJob的apiVersionkind: cronjob #当前类型CronJobmetadata: name:testspec: schedule: "*/1 * * * *" #运行时间, format and Linux consistent jobtemplate: #job模板 Spec: Template: Spec: containners: -name:test image:nginx command: ["echo", "This is Test"] Restartpolicy: OnFailure
Needs to be added in the Kube-aoiservier configuration file
Kubectl api-version #查看当前所有api-version Support BATCH/V2ALPHA1
Kubectl Get Cronjob
The principle of kubernetes job