<p>I have a bunch of services deployed to a Kubernetes cluster (various pods and services all load-balanced behind a gateway). I am making a REST call to one of them and getting unexpected errors, but the problem is I'm not actually sure <em>which</em> pod/service is actually throwing the error. I would like to check all the logs of every pod/service.</p>
<p>When I run <code>kubectl get namespace</code> I get:</p>
<pre><code>NAME               STATUS     AGE
another-app        Active     22d
myapp              Active     22d
myapp-database     Active     22d
default            Active     22d
kube-public        Active     22d
kube-system        Active     22d
zanzabar           Active     22d
</code></pre>
<p>Is there a <code>kubectl log</code> command that can scan the entire cluster for logs and search them for a specific error message? For instance, say the error message I'm getting back from the REST (<code>curl</code>) is &quot;Sorry mario your princess is in another castle&quot;. Is there any way I can use <code>kubectl log</code> to scan all pod/service logs for that phrase and display the results back to me? If not, then whats the best/easiest way <strong>using <code>kubectl</code></strong> to find the pod/service with the error message (and hopefully, more details behind my error)?</p>

hotmeatballsoup
<p>You can fetch the logs of a particular pod or container(use -c flag for container) and grep the error logs by pipelining the log command with the grep command.</p>
<p>For example if I want to get logs of a pod with name my-pod and want to grep &quot;error exists&quot; word then command goes like:</p>
<pre><code>kubectl logs my-pod | grep “error exist” 
</code></pre>
<p>Refer this <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/#interacting-with-running-pods" rel="nofollow noreferrer">document</a> for multiple ways of fetching logs and this <a href="https://stackoverflow.com/questions/53348331/extract-lines-from-kubernetes-log">similar question</a> for more information on grep usage.</p>
