49 lines
1.3 KiB
Markdown
49 lines
1.3 KiB
Markdown
|
---
|
|||
|
title: "Job"
|
|||
|
---
|
|||
|
|
|||
|
Job负责批处理任务,即仅执行一次的任务,它保证批处理任务的一个或多个Pod成功结束。
|
|||
|
|
|||
|
## Job Spec格式
|
|||
|
|
|||
|
- spec.template格式同Pod
|
|||
|
- RestartPolicy仅支持Never或OnFailure
|
|||
|
- 单个Pod时,默认Pod成功运行后Job即结束
|
|||
|
- `.spec.completions`标志Job结束需要成功运行的Pod个数,默认为1
|
|||
|
- `.spec.parallelism`标志并行运行的Pod的个数,默认为1
|
|||
|
- `spec.activeDeadlineSeconds`标志失败Pod的重试最大时间,超过这个时间不会继续重试
|
|||
|
|
|||
|
一个简单的例子:
|
|||
|
|
|||
|
```yaml
|
|||
|
apiVersion: batch/v1
|
|||
|
kind: Job
|
|||
|
metadata:
|
|||
|
name: pi
|
|||
|
spec:
|
|||
|
template:
|
|||
|
metadata:
|
|||
|
name: pi
|
|||
|
spec:
|
|||
|
containers:
|
|||
|
- name: pi
|
|||
|
image: perl
|
|||
|
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
|
|||
|
restartPolicy: Never
|
|||
|
```
|
|||
|
|
|||
|
```
|
|||
|
$ kubectl create -f ./job.yaml
|
|||
|
job "pi" created
|
|||
|
$ pods=$(kubectl get pods --selector=job-name=pi --output=jsonpath={.items..metadata.name})
|
|||
|
$ kubectl logs $pods
|
|||
|
3.141592653589793238462643383279502...
|
|||
|
```
|
|||
|
|
|||
|
## Bare Pods
|
|||
|
|
|||
|
所谓Bare Pods是指直接用PodSpec来创建的Pod(即不在ReplicaSets或者ReplicationCtroller的管理之下的Pods)。这些Pod在Node重启后不会自动重启,但Job则会创建新的Pod继续任务。所以,推荐使用Job来替代Bare Pods,即便是应用只需要一个Pod。
|
|||
|
|
|||
|
|
|||
|
|