<p>I am interested in grabbing the logs of multiple pods that contain &quot;test&quot; in name, but using json and jq. The first step was to find out the names that contain that particular string - in my case, &quot;test&quot;:</p>
<pre><code>kubectl get pods -n test -o json | jq '.items[] | select(.metadata.name|test(&quot;test&quot;))| .metadata.name'
</code></pre>
<p>I had this answer with the help of someone on Stackoverflow.</p>
<p>Now I would like to find out the command that grabs the logs of each of these pods that contain &quot;test&quot; name. I would like to have something like the following command, but unfortunately this way doesn't work as I guess the first command return all pods in one go on multiple lines:</p>
<pre><code>kubectl logs ``kubectl get pods -n test -o json | jq '.items[] | select(.metadata.name|test(&quot;test&quot;))| .metadata.name'`` -n test
</code></pre>
<p>Is any way to get the logs in this way with some extra arguments to make it work?</p>
<p>Thanks.</p>

Albert
<p>Use a loop to get all pod's log, try this:</p>
<pre><code>for pod in `kubectl get po -o json |  jq '.items[] | select(.metadata.name|contains(&quot;test&quot;))| .metadata.name' | sed 's/&quot;//g'` ; do
  echo $pod
  kubectl logs $pod 
done
</code></pre>
