-
-
Save StevenACoffman/b51cdeabc49abf66f45a171a76e04858 to your computer and use it in GitHub Desktop.
Filter failed kubernetes jobs to delete it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Should be a job too :-D | |
# With xargs (on all namespaces) | |
kc get jobs -o=jsonpath='{range .items[?(@.status.conditions[0].type == "Failed")]}{.metadata.name}{"\t"}{.metadata.namespace}{"\n"}{end}' --all-namespaces | \ | |
xargs -n2 sh -c 'kubectl delete jobs $0 --namespace=$1' | |
# For loop (only in the current namespace) | |
for i in $(kc get jobs -o=jsonpath='{range .items[?(@.status.conditions[0].type == "Failed")]}{.metadata.name}{"\n"}{end}'); | |
do kubectl delete jobs $i; done | |
# Delete jobs whose age is measured in days (could still be actively running!) | |
export NAMESPACE='demographics' | |
kubectl get job -n $NAMESPACE | awk 'match($4,/[0-9]+d/) {print $1}' | xargs kubectl delete job -n $NAMESPACE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment