<p>I can sort my Kubernetes pods by name using:</p>

<pre><code>kubectl get pods --sort-by=.metadata.name
</code></pre>

<p>How can I sort them (or other resoures) by age using <code>kubectl</code>?</p>

<p>Pods have status, which you can use to find out startTime.</p>
<p>I guess something like <code>kubectl get po --sort-by=.status.startTime</code> should work.</p>
<p>You could also try:</p>
<ol>
<li><code>kubectl get po --sort-by='{.firstTimestamp}'</code>.</li>
<li><code>kubectl get pods --sort-by=.metadata.creationTimestamp</code> Thanks @chris</li>
</ol>
<p>Also apparently in Kubernetes 1.7 release, sort-by is broken.</p>
<p><a href="https://github.com/kubernetes/kubectl/issues/43" rel="noreferrer">https://github.com/kubernetes/kubectl/issues/43</a></p>
<p>Here's the bug report : <a href="https://github.com/kubernetes/kubernetes/issues/48602" rel="noreferrer">https://github.com/kubernetes/kubernetes/issues/48602</a></p>
<p>Here's the PR: <a href="https://github.com/kubernetes/kubernetes/pull/48659/files" rel="noreferrer">https://github.com/kubernetes/kubernetes/pull/48659/files</a></p>
