<p>I have a use case where I want to check which pods are covered by a network policy, right now my focus is only k8s generated network policies.</p>
<p>What's the easiest way to do this? I know we can go through each network policy and from there filter out pods but a network policy can have multiple ways in which one uses the pod filtering. I am not sure if there is a way to tackle every possible pod filter on the network policy and then get the list of the pods from it.</p>

<p>Using the <strong>podSelector</strong> field you can check all the pods that are covered by a Network Policy. Using the label mentioned in podSelector you can retrieve the list of pods which are using the NetworkPolicy.</p>
<p>Each NetworkPolicy includes a <strong>podSelector</strong> which selects the grouping of pods to which the policy applies. Let us consider an example policy which contains a <strong>podSelector</strong> with the label “role=db”. The example policy selects pods with the label &quot;role=db&quot;. An empty podSelector selects all pods in the namespace.</p>
<p>When you run NetworkPolicy, you can check the label used for a podSelector by describing the networkpolicy.</p>
<pre><code>$ kubectl describe networkpolicy &lt;networkpolicy-name&gt;
</code></pre>
<p>Pod selector will show you which labels this network policy applied too. Then you can present all the pods with this label by:</p>
<pre><code>$ kubectl get pods -l &lt;podSelector&gt;
</code></pre>
<p>Refer <a href="https://kubernetes.io/docs/concepts/services-networking/network-policies/#networkpolicy-resource" rel="nofollow noreferrer">NetworkPolicy resource</a> for more information.</p>
