Skip to content

Instantly share code, notes, and snippets.

@alexey-igrychev
Created November 1, 2019 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexey-igrychev/629f6cf183e53f15ae40db675e810a6d to your computer and use it in GitHub Desktop.
Save alexey-igrychev/629f6cf183e53f15ae40db675e810a6d to your computer and use it in GitHub Desktop.
#!/bin/bash
namespacePrefix=${1:-test-}
deltaTS=${2:-$((60 * 60 * 24))}
namespaces=$(kubectl get namespace -o json | jq -r "[.items[] | {name: .metadata.name, startTime: .metadata.creationTimestamp | fromdate } | select(.startTime < (now | . - $deltaTS))]" | jq -r ".[].name" | grep $namespacePrefix)
for namespace in $namespaces; do
kubectl delete ns $namespace
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment