Team Neptune needs a Job template located at /opt/course/3/job.yaml
. This Job should run image busybox:1.31.0
and execute sleep 2 && echo done
. It should be in namespace neptune
, run a total of 3 times and should execute 2 runs in parallel.
Start the Job and check its history. Each pod created by the Job should have the label 'id: awesome-job'. The job should be named 'neb-new-job' and the container 'neb-new-job-container'.
k -n neptun create job -h
# check the export on the very top of this document so we can use $do
k -n neptune create job neb-new-job --image=busybox:1.31.0 $do > /opt/course/3/job.yaml -- sh -c "sleep 2 && echo done"
vim /opt/course/3/job.yaml
Make the required changes in the yaml:
# /opt/course/3/job.yaml
apiVersion: batch/v1
kind: Job
metadata:
creationTimestamp: null
name: neb-new-job
namespace: neptune # add
spec:
completions: 3 # add
parallelism: 2 # add
template:
metadata:
creationTimestamp: null
labels: # add
id: awesome-job # add
spec:
containers:
- command:
- sh
- -c
- sleep 2 && echo done
image: busybox:1.31.0
name: neb-new-job-container # update
resources: {}
restartPolicy: Never
status: {}
Then to create it:
k -f /opt/course/3/job.yaml create # namespace already set in yaml
Check Job and Pods, you should see two running parallel at most but three in total:
➜ k -n neptune get pod,job | grep neb-new-job
pod/neb-new-job-jhq2g 0/1 ContainerCreating 0 4s
pod/neb-new-job-vf6ts 0/1 ContainerCreating 0 4s
job.batch/neb-new-job 0/3 4s 5s
➜ k -n neptune get pod,job | grep neb-new-job
pod/neb-new-job-gm8sz 0/1 ContainerCreating 0 0s
pod/neb-new-job-jhq2g 0/1 Completed 0 10s
pod/neb-new-job-vf6ts 1/1 Running 0 10s
job.batch/neb-new-job 1/3 10s 11s
➜ k -n neptune get pod,job | grep neb-new-job
pod/neb-new-job-gm8sz 0/1 Completed 0 12s
pod/neb-new-job-jhq2g 0/1 Completed 0 22s
pod/neb-new-job-vf6ts 0/1 Completed 0 22s
job.batch/neb-new-job 3/3 21s 23s
Check history:
➜ k -n neptune describe job neb-new-job
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 2m52s job-controller Created pod: neb-new-job-jhq2g
Normal SuccessfulCreate 2m52s job-controller Created pod: neb-new-job-vf6ts
Normal SuccessfulCreate 2m42s job-controller Created pod: neb-new-job-gm8sz
At the age column we can see that two pods run parallel and the third one after that. Just as it was required in the task.