<p>We have created pvc and they are in pending state. So in order to check the state we execute</p>
<pre><code>Kubectl describe -f &lt;pvc.yml&gt;
</code></pre>
<p>it displays result as below</p>
<pre><code>Name:          myproj-pvc-2020-09-29-04-02-1601377369-49419-1
Namespace:     default
StorageClass:  myproj-storageclass-2020-09-29-04-02-1601377366
Status:        Pending
Volume:
Labels:        ansible=csitest-2020-09-29-04-02-1601377369-49419-1
               pvcRef=csi-pvc-ansibles-1
Annotations:   volume.beta.kubernetes.io/storage-provisioner: csi.myorg.com
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode:    Filesystem
Mounted By:    &lt;none&gt;
Events:
  Type     Reason                Age                  From                                                                                   Message
  ----     ------                ----                 ----                                                                                   -------
  Normal   Provisioning          85s (x8 over 4m43s)  csi.myorg.com_csicentos76w3.mylab.myprojstorage.com_2e1a7c1d-7542-42a5-a2e1-491e1d04b4ee  External provisioner is provisioning volume for claim &quot;default/myproj-pvc-2020-09-29-04-02-1601377369-49419-1&quot;
  Warning  ProvisioningFailed    74s (x8 over 4m33s)  csi.myorg.com_csicentos76w3.mylab.myprojstorage.com_2e1a7c1d-7542-42a5-a2e1-491e1d04b4ee  failed to provision volume with StorageClass &quot;myproj-storageclass-2020-09-29-04-02-1601377366&quot;: rpc error: code = Unavailable desc = Failed to get storage provider from secrets, Request failed with status code 401 and errors Error code (Unauthorized) and message (HTTP 401 Unauthorized.)
  Normal   ExternalProvisioning  6s (x20 over 4m43s)  persistentvolume-controller                                                            waiting for a volume to be created, either by external provisioner &quot;csi.myorg.com&quot; or manually created by system administrat
</code></pre>
<p>What I need is to filter only events of this pvc.yaml?  If i execute <code>kubectl get -f pvc.yaml -o json</code> it doesn't display error events in json</p>
<p>I can do <code>kubectl describe -f &lt;pvc.yml&gt; | grep -A10 Events:</code>  but there is no guarantee that only 10 lines will be always error.</p>
<p>Also i found this way <code>kubectl get events --field-selector involvedObject.kind=&quot;PersistentVolumeClaim&quot;</code> but this will show all events related to all pvc. I need to get events of Pvc list mentioned in pvc.yml file.</p>
<p>How to filter events of all pvc in pvc.yaml?</p>

<p><code>kubectl get -f pvc.yaml -o json</code> does work, but I assume you meant <code>kubectl get events -f pvc.yaml -o json</code></p>
<p>kubectl doesn't seem to allow for such filtering. You may want to open a feature request on <a href="https://github.com/kubernetes/kubectl/issues" rel="nofollow noreferrer">kubectl github issues</a>.</p>
<p>But meanwhile, here is what I came up with as an alternative:</p>
<pre><code>kubectl get -f &lt;pvc.yml&gt; -ojson \
 | jq &quot;.items[] | .metadata.name&quot; \
 | xargs -I{} kubectl get events --field-selector involvedObject.kind=&quot;PersistentVolumeClaim&quot;,involvedObject.name={} --no-headers --ignore-not-found
</code></pre>
<p>Notce that you need <code>jq</code> installed. You could also use <code>yq</code> and you wouldn't need this first trick with conversion to json but you would need to slightly adjust yq filter. I also assume you have kubectl installed and of course xargs which should be available by default on all linux machines.</p>
