job creates one or more pods and ensures that a specified number of them successfully terminate. As pods successfully complete, the job tracks the successful completions. When a specified number of successful completions is reached, the job itself is complete. Deleting a Job will cleanup the pods it created.
Let’s start by creating the job-whalesay.yaml manifest using this command
mkdir ~/environment/batch_policy/ cat <<EoF > ~/environment/batch_policy/job-whalesay.yaml apiVersion: batch/v1 kind: Job metadata: name: whalesay spec: template: spec: containers: - name: whalesay image: docker/whalesay command: ["cowsay", "This is a Kubernetes Job!"] restartPolicy: Never backoffLimit: 4 EoF
Run a sample Kubernetes Job using the
kubectl apply -f ~/environment/batch_policy/job-whalesay.yaml
Wait until the job has completed successfully.
kubectl get job/whalesay
Confirm the output.
kubectl logs -l job-name=whalesay