Skip to content

Instantly share code, notes, and snippets.

@redsfyre
Created November 5, 2021 14:05
Show Gist options
  • Save redsfyre/81bc2dd2111b5b06460a4503df6fba5e to your computer and use it in GitHub Desktop.
Save redsfyre/81bc2dd2111b5b06460a4503df6fba5e to your computer and use it in GitHub Desktop.
Script that stops (suspends) all running kubernetes cronjobs
#!/bin/bash
for ns in $(kubectl get ns -o jsonpath="{.items[*].metadata.name}"); do
for cj in $(kubectl get cronjobs -n "$ns" -o name); do
kubectl patch "$cj" -n "$ns" -p '{"spec" : {"suspend" : true }}';
done
done
#!/bin/bash
for line in $(cat crons.txt); do
kubectl patch cronjob.batch/"$line" -p '{"spec" : {"suspend" : false }}';
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment