Skip to content

Instantly share code, notes, and snippets.

@dbowling
Created June 30, 2026 20:09
Show Gist options
  • Select an option

  • Save dbowling/79832378f6724dced0ec28b570ffac05 to your computer and use it in GitHub Desktop.

Select an option

Save dbowling/79832378f6724dced0ec28b570ffac05 to your computer and use it in GitHub Desktop.
Kubernetes Job that demonstrates activeDeadlineSeconds with a graceful termination
apiVersion: batch/v1
kind: Job
metadata:
name: dan-graceful-term-test
namespace: sandbox
labels:
app: graceful-shutdown
spec:
backoffLimit: 0
activeDeadlineSeconds: 15
template:
spec:
restartPolicy: Never
terminationGracePeriodSeconds: 20
containers:
- name: sigterm-test
image: busybox:1.36
command: ["/bin/sh", "-c"]
args:
- |
handle_term() {
echo "[$(date -u +%H:%M:%S)] SIGTERM received - starting graceful shutdown"
sleep 3
echo "[$(date -u +%H:%M:%S)] graceful shutdown complete, exiting 0"
exit 0
}
trap handle_term TERM
echo "[$(date -u +%H:%M:%S)] container started - sleeping..."
# Sleep would block if not in the background
sleep 300 &
wait $!
echo "[$(date -u +%H:%M:%S)] sleep finished on its own - this shouldn't happen"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment