<p>Is it possible to delete POD in kubernetes based on creation time or age? </p>

<p>Example : I would like to delete all PODs which are older than 1 day. These PODs are orphaned , therefore no new PODs will be created. </p>

<p>This command will delete all PODs older than one day :</p>

<pre><code>kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}} {{.metadata.creationTimestamp}}{{"\n"}}{{end}}' | awk '$2 &lt;= "'$(date -d 'yesterday' -Ins --utc | sed 's/+0000/Z/')'" { print $1 }' | xargs --no-run-if-empty kubectl delete pod
</code></pre>

<p>This command will delete all PODs older than 4 hours :</p>

<pre><code>kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}} {{.metadata.creationTimestamp}}{{"\n"}}{{end}}' | awk '$2 &lt;= "'$(date -d'now-4 hours' -Ins --utc | sed 's/+0000/Z/')'" { print $1 }' | xargs --no-run-if-empty kubectl delete pod
</code></pre>
