

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Jobs
incomplete
2: CronJobs
incomplete
This lesson's interactive features are locked, please to keep using them
Every app we've deployed so far is supposed to run forever. If the web server exits, it means something's wrong, and Kubernetes restarts it.
But some work is supposed to finish, things like:
A database migration
A one-off data cleanup
A nightly report
For that, there's the Job. A Job creates a pod and keeps retrying until it exits successfully (with exit code 0). Then it's done, and the pod just sits there in a Completed state so you can read its logs.
Jobs have a few important parts of their configuration:
A backoffLimit can be set, which is how many times to retry before giving up and marking the Job as failed (the default is 6).
While a Deployment's pods always restart, a Job's pods have a restartPolicy that must be set to either:
Never: start a new pod on failure
OnFailure: restart the container in the same pod
Run a one-off stats report.
apiVersion: batch/v1
kind: Job
metadata:
name: synergychat-stats
spec:
backoffLimit: 4
template:
spec:
restartPolicy: Never
containers:
- name: synergychat-stats
image: curlimages/curl:latest
args:
- -sf
- http://crawler-service.crawler.svc.cluster.local/statsThis Job uses the curl image to fetch the crawler's keyword stats and print them.
kubectl logs job/synergychat-statsMake sure kubectl proxy is running, then run and submit the CLI tests.