Skip to content

Commit a2d59a0

Browse files
committed
feat: Add Job with generated name
1 parent a89143f commit a2d59a0

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,40 @@ kubectl wait --for=condition=complete --timeout=600s job/pi
973973

974974
You have to set `ttlSecondsAfterFinished` in job spec.
975975

976+
### Job With Generated Name
977+
978+
Create (not apply) job
979+
980+
```
981+
kubectl create -f job-generate-name.yml
982+
```
983+
984+
Delete all jobs
985+
986+
```
987+
kubectl delete job --all
988+
```
989+
990+
Example
991+
992+
```
993+
ondrej@sika-mac-air:~$ kubectl create -f job-generate-name.yml
994+
job.batch/hello-4hjd4 created
995+
ondrej@sika-mac-air:~$ kubectl create -f job-generate-name.yml
996+
job.batch/hello-nrr8r created
997+
ondrej@sika-mac-air:~$ kubectl create -f job-generate-name.yml
998+
job.batch/hello-h8mjd created
999+
ondrej@sika-mac-air:~$ kubectl get job
1000+
NAME COMPLETIONS DURATION AGE
1001+
hello-4hjd4 1/1 1s 5s
1002+
hello-h8mjd 1/1 2s 3s
1003+
hello-nrr8r 1/1 2s 4s
1004+
ondrej@sika-mac-air:~$ kubectl delete job --all
1005+
job.batch "hello-4hjd4" deleted
1006+
job.batch "hello-h8mjd" deleted
1007+
job.batch "hello-nrr8r" deleted
1008+
```
1009+
9761010
### Create Cron Job
9771011

9781012
- <https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/>

job-generate-name.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
generateName: hello-
5+
spec:
6+
template:
7+
metadata:
8+
name: hello
9+
spec:
10+
containers:
11+
- name: main
12+
image: debian:11-slim
13+
command: ["/bin/sh", "-c"]
14+
args:
15+
- |
16+
echo Hello World!
17+
restartPolicy: Never

0 commit comments

Comments
 (0)