<p>Using <code>kubectl</code>, I want to <code>describe</code> one of the pods (can be a random one) filtered on a labelSelector. Currently, I perform it in two steps:</p>
<ol>
<li><code>get</code> the pods,</li>
<li>Copy the name of one of the results, and <code>describe</code> it.</li>
</ol>
<pre class="lang-bash prettyprint-override"><code>$ kubectl get pods -l app=my-app,environment=production
$ kubectl describe pods my-pod-name-copied-from-the-results
</code></pre>
<p>Can I do that with a one-liner, and without copying the pod name every single time?</p>

vahdet
<p>Well, you could try something like this:</p>
<p><strong>Note:</strong> This works for a single pod only!</p>
<pre class="lang-bash prettyprint-override"><code>kubectl describe pods $(basename $(kubectl get pods -l job-name=curl-job -o name --no-headers))
</code></pre>
<p>Explanation:</p>
<pre class="lang-bash prettyprint-override"><code>kubectl get pods -l job-name=curl-job -o name --no-headers
</code></pre>
<p>Returns the name of a pod with a given label, for example:</p>
<p><code>pod/curl-job-p5rsb</code></p>
<p>But if you use just this, you'll get:</p>
<pre><code>error: there is no need to specify a resource type as a separate argument when passing arguments in resource/name form 
</code></pre>
<p>So, we use <code>basename</code> to get rid of the <code>pod/</code> part:</p>
<p>Running:</p>
<pre class="lang-bash prettyprint-override"><code>basename $(kubectl get pods -l job-name=curl-job -o name --no-headers)
</code></pre>
<p>Returns:</p>
<pre><code>curl-job-p5rsb
</code></pre>
<p>Now, you can pass this as an argument to <code>kubectl describe pods</code></p>
<p>This completes the entire command.</p>
<pre class="lang-bash prettyprint-override"><code>kubectl describe pods \
   $(basename $(kubectl get pods -l job-name=curl-job -o name --no-headers))
</code></pre>
<hr />
<p>EDIT:</p>
<p>If you want to get the top pod out of many pods, use <code>head -n 1</code>, like this:</p>
<pre class="lang-bash prettyprint-override"><code>kubectl describe pods $(basename $(kubectl get pods -l stage=test8 -o name --no-headers | head -n 1))
</code></pre>
