DevilKing's blog

冷灯看剑,剑上几分功名?炉香无需计苍生,纵一穿烟逝,万丈云埋,孤阳还照古陵

0%

K8s Batch Jobs in Background

原文链接

a batch-job in a few different ways: one-time, sequential, and parallel.

single-job

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
apiVersion: batch/v1
kind: Job
metadata:
name: single-job
spec:
backoffLimit: 6
# number of retries before throwing error

activeDeadlineSeconds: 10 # time to allow job to run

template:
metadata:
labels:
app: kubernetes-series
tier: job
spec:
restartPolicy: OnFailure
containers:
- name: job
image: gcr.io/PROJECT_NAME/batchjob-container-job:latest

# environment variables for the Pod

env:
- name: GCLOUD_PROJECT
value: PROJECT_NAME
- name: MESSAGE
value: I am a single run job
- name: FOREIGN_SERVICE
value: http://endpoints.default.svc.cluster.local/single
- name: NODE_ENV
value: production
ports:
- containerPort: 80

sequential-job

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
apiVersion: batch/v1
kind: Job
metadata:
name: sequential-job
spec:

completions: 3 # number of times to run
backoffLimit: 6 # number of retries before throwing error
activeDeadlineSeconds: 10 # time to allow job to run
template:
metadata:
labels:
app: kubernetes-series
tier: job
spec:
restartPolicy: OnFailure
containers:
- name: job
image: gcr.io/PROJECT_NAME/batchjob-container-job:latest
# environment variables for the Pod
env:
- name: GCLOUD_PROJECT
value: PROJECT_NAME
- name: MESSAGE
value: I am a sequential run job
- name: FOREIGN_SERVICE
value: http://endpoints.default.svc.cluster.local/sequential
- name: NODE_ENV
value: production
ports:
- containerPort: 80

parallel-job

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
apiVersion: batch/v1
kind: Job
metadata:
name: parallel-job
spec:
completions: 6 # number of times to run

parallelism: 2 # number of pods that can run in parallel
backoffLimit: 6 # number of retries before throwing error
activeDeadlineSeconds: 10 # time to allow job to run
template:
metadata:
labels:
app: kubernetes-series
tier: job
spec:
restartPolicy: OnFailure
containers:
- name: job
image: gcr.io/PROJECT_NAME/batchjob-container-job:latest
# environment variables for the Pod
env:
- name: GCLOUD_PROJECT
value: PROJECT_NAME
- name: MESSAGE
value: I am a parallel run job
- name: FOREIGN_SERVICE
value: http://endpoints.default.svc.cluster.local/parallel
- name: NODE_ENV
value: production
ports:
- containerPort: 80