<p>I need to view logs a pod of specific name:
Basically, I want to see logs for the pod having name <code>infra</code> in it.</p>
<p>I'm using below command:</p>
<pre><code>kubectl logs $(kubectl get pods | awk '{print $1}' | grep -e &quot;infra&quot;)
</code></pre>
<p>But, it's not working.</p>

Temp Expt
<p>The <a href="https://github.com/stern/stern" rel="nofollow noreferrer"><code>stern</code></a> command make this very simple:</p>
<pre><code>stern infra
</code></pre>
<p>That will stream the logs from any pods that have <code>infra</code> in the name.</p>
<hr />
<p>But even without <code>stern</code>, you can do something like:</p>
<pre><code>kubectl logs $(kubectl get pods -o name | grep infra)
</code></pre>
<p>That will work as long as your <code>grep</code> command returns a single line. If the <code>grep</code> command results in multiple matches, you'll need to use a more specific pattern.</p>
<p>If you want to see logs from multiple pods with a single command, you can request logs by label using <code>kubectl logs -l &lt;label&gt;</code>. E.g., if I have several pods with the label <code>app=my-app</code>, I can run:</p>
<pre><code>kubectl logs -l app=my-app
</code></pre>
