<p>When running <code>kubectl get events</code>, is there a way to filter by events without knowing the name of the pod?</p>

<p>I am trying to do this with <a href="https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/kubernetes?view=azure-devops" rel="nofollow noreferrer">Azure Pipeline's <strong>Kubectl</strong> task</a>, which is limited to passing arguments to <code>kubectl get events</code>, but does not allow subshells and pipes, so <code>grep</code> and <code>awk</code> are not available.</p>

<p>I tried using <code>kubectl get events --field-selector involvedObject.name=my-microservice-name</code>, which works to an extent (i.e., for the deployment resource), but not for the pods.</p>

<p>Using <code>kubectl get events --field-selector app.kubernetes.io/name=my-microservice-name</code> returns no results, despite having that label configured as seen in <code>kubectl describe pod &lt;my-microservice-name&gt;-pod-name</code>.</p>

<p>Ideally if there is a way to use wildcards, such as <code>kubectl get events --field-selector involvedObject.name=*my-microservice-name*</code>, would be the best case scenario.</p>

<p>Any help is greatly appreciated.</p>

<p>Thanks!</p>

<p>I don't have azure environment, but I can show events on pods</p>

<pre><code>master $ kubectl get events --field-selector involvedObject.kind=Pod
LAST SEEN   TYPE     REASON      OBJECT      MESSAGE
&lt;unknown&gt;   Normal   Scheduled   pod/nginx   Successfully assigned default/nginx to node01
5m13s       Normal   Pulling     pod/nginx   Pulling image "nginx"
5m8s        Normal   Pulled      pod/nginx   Successfully pulled image "nginx"
5m8s        Normal   Created     pod/nginx   Created container nginx
5m8s        Normal   Started     pod/nginx   Started container nginx
</code></pre>

<p>If you need target on particular pod, you should work with <code>involvedObject.kind</code> and <code>involvedObject.name</code> together. </p>

<pre><code>master $ kubectl run redis --image=redis --generator=run-pod/v1
master $ kubectl run nginx --image=nginx --generator=run-pod/v1
master $ kubectl get events --field-selector involvedObject.kind=Pod,involvedObject.name=nginx
LAST SEEN   TYPE     REASON      OBJECT      MESSAGE
&lt;unknown&gt;   Normal   Scheduled   pod/nginx   Successfully assigned default/nginx to node01
16m         Normal   Pulling     pod/nginx   Pulling image "nginx"
16m         Normal   Pulled      pod/nginx   Successfully pulled image "nginx"
16m         Normal   Created     pod/nginx   Created container nginx
16m         Normal   Started     pod/nginx   Started container nginx
</code></pre>

<p>Why I knew <code>involvedObject.kind</code> works, because its json output shows the key is exist</p>

<pre><code>        "involvedObject": {
            "apiVersion": "v1",
            "fieldPath": "spec.containers{nginx}",
            "kind": "Pod",
            "name": "nginx",
            "namespace": "default",
            "resourceVersion": "604",
            "uid": "7ebaaf99-aa9c-402b-9517-1628d99c1763"
        },
</code></pre>

<p>The other way you need try is <code>jsonpath</code>, get the output as json format</p>

<pre><code>kubectl get events -o json
</code></pre>

<p>then copy &amp; paste the json to <a href="https://jsonpath.com/" rel="nofollow noreferrer">https://jsonpath.com/</a> and play around with <a href="https://kubernetes.io/docs/reference/kubectl/jsonpath/" rel="nofollow noreferrer">jsonpath practices</a></p>
