<p>I would like to list pods created within 24 hours. I didn't find any kubectl commands or anything to get those. Could anyone please help me with the kubectl command to get only the pods created in last 24 hours.</p>

Vivek Subramani
<p>In order to list all Pods created within the last 24h you can use the below command:</p>
<pre><code>kubectl get pods --sort-by=.metadata.creationTimestamp | awk 'match($5,/^[0-9]h|^[0-9][0-9]h|^[0-9]m|^[0-9][0-9]m|^[0-9]s|^[0-9][0-9]s/) {print $0}'
</code></pre>
<p>If you also want to get Pods with errors only than you can use:</p>
<pre><code>kubectl get pods --sort-by=.metadata.creationTimestamp | awk 'match($5,/^[0-9]h|^[0-9][0-9]h|^[0-9]m|^[0-9][0-9]m|^[0-9]s|^[0-9][0-9]s/) {print $0}' | grep -i Error
</code></pre>
<p>Or alternatively to only list Pods with the <code>Pending</code> status:</p>
<pre><code>kubectl get pods --field-selector=status.phase=Pending --sort-by=.metadata.creationTimestamp | awk 'match($5,/^[0-9]h|^[0-9][0-9]h|^[0-9]m|^[0-9][0-9]m|^[0-9]s|^[0-9][0-9]s/) {print $0}'
</code></pre>
