Sub topic 15
Suspending and resuming a Job
This chapter assumes you can write a basic Job manifest and use kubectl to apply, patch, and inspect resources. It also assumes you know what completions, parallelism, and activeDeadlineSeconds do.
What suspend does
A Job has a field, spec.suspend, that pauses it without deleting it. While suspend is true, the Job controller creates no Pods. You can pause a Job in two ways:
- Create it already suspended, so it waits until you or another tool releases it.
- Set
suspend: trueon a running Job to stop it temporarily.
The field defaults to false. Suspending a Job keeps the Job object, its history, and its progress counters.
Creating a Job in the suspended state
This Job needs 3 successful Pods. It creates none until someone sets suspend to false.
apiVersion: batch/v1
kind: Job
metadata:
name: suspended-demo
spec:
suspend: true
completions: 3
parallelism: 1
activeDeadlineSeconds: 600
template:
spec:
restartPolicy: Never
containers:
- name: worker
image: busybox:1.36
command: ["sh", "-c", "echo working; sleep 20"]After kubectl apply, kubectl get pods --selector=job-name=suspended-demo returns nothing. kubectl describe job suspended-demo shows a Suspended condition and an event saying the Job was suspended.
Resuming and suspending with kubectl
Change the field with kubectl patch:
# Resume: the controller starts creating Pods
kubectl patch job suspended-demo -p '{"spec":{"suspend":false}}'
# Suspend again while it runs
kubectl patch job suspended-demo -p '{"spec":{"suspend":true}}'
# Check the result
kubectl get job suspended-demo
kubectl describe job suspended-demoWhat happens to running Pods
When you suspend a Job that has active Pods, the controller deletes them. Each Pod gets a termination signal (SIGTERM) and its normal grace period to shut down. A Pod that was deleted this way does not count as a success, so its work is lost unless the container saved it somewhere.
Pods that already succeeded are kept and still count toward completions. For example, suppose you suspend a 6-completion Job after 2 successes. When you resume it, the controller only needs 4 more.
The deadline timer resets
activeDeadlineSeconds counts time while the Job is active. Suspending the Job stops that clock, and resuming it starts the clock again from zero. A Job with a 600-second deadline gets a fresh 600 seconds each time you resume it.
Where suspend is useful
- Queueing and admission. Tools such as Kueue create Jobs suspended and release them when cluster capacity is available.
- Freeing resources. You can pause a heavy batch Job during a peak period and resume it later.
- Adjusting scheduling. While a Job is suspended, you can edit scheduling fields in its Pod template, such as
nodeSelector, tolerations, and affinity. Kubernetes blocks these edits on a Job that is already running. Check that your cluster version supports this.
Suspending a CronJob is different
A CronJob has its own spec.suspend field. It stops the CronJob from creating new Jobs. It does not touch Jobs that already started. To pause a CronJob run that is in progress, patch the Job that it created.
Exercise
A Job with completions: 5 has finished 2 Pods successfully and has 1 Pod running. You set suspend to true and later set it back to false. How many more successful Pods does the Job need, and what happened to the running Pod?
Show answer
It needs 3 more. The 2 successful Pods are kept and still count. The running Pod was deleted when you suspended the Job, and any unsaved work in it was lost. After you resume, the controller creates new Pods for the remaining completions.