Created
November 20, 2019 14:08
-
-
Save pascalwhoop/282d1cc3f6db790d3a544cbd8d00e662 to your computer and use it in GitHub Desktop.
Cleans the Kubernetes API of all pods in a namespace (in our case airflow)
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
NAMESPACE=airflow | |
#edit the > 3 < in the jq statement to correspond to the number of days you want to keep pods around for | |
kubectl delete pod -n $NAMESPACE $(kubectl get pods -n $NAMESPACE -o json | jq -r '.items[] | | |
select(.status.phase != "Running") | | |
select(last(.status.containerStatuses)[].state | has("terminated")) | | |
select((last(.status.containerStatuses)[].state.terminated.finishedAt | fromdate) < (now - 60*60*24*3)) | | |
.metadata.name') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment