kubernetes-handbook/architecture/job.md

47 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 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。