<p>I am running a deployment called <em>mydeployment</em> that manages several pods/replicas for a certain service. I want to search all the service pods/instances/replicas of that deployment for a certain keyword. The command below defaults to one replica and returns the keyword matching in this replica only.</p>
<pre><code>Kubectl logs -f deploy/mydeployment | grep &quot;keyword&quot;
</code></pre>
<p>Is it possible to customize the above command to return all the matching keywords out of all instances/pods of the deployment <em>mydeployment</em>? Any hint?</p>

Mazen Ezzeddine
<p>Save this to a file <code>fetchLogs.sh</code> file, and if you are using Linux box, use <code>sh fetchLogs.sh</code></p>
<pre class="lang-sh prettyprint-override"><code>#!/bin/sh

podName=&quot;key-word-from-pod-name&quot;
keyWord=&quot;actual-log-search-keyword&quot;
nameSpace=&quot;name-space-where-the-pods-or-running&quot;
echo &quot;Running Script..&quot;
for podName in `kubectl get pods -A -o name | grep -i ${podName} | cut -d'/' -f2`;
do
       echo &quot;searching pod ${podName}&quot;
       kubectl -n ${nameSpace} logs pod/${podName} | grep -i ${keyWord}
done

</code></pre>
<p>I used the pods, if you want to use deployment, the idea is same change the <code>kubectl</code> command accordingly.</p>
