<p>I am new to configuring network policies in k8s. I have to make a change in production which I cant test. Basically we need to block all UDP traffic going to the pods in a specific namespace. Would the below work?</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: deny-all-udp
  namespace: foxden-loadtest
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  ingress:
    ports:
    - protocol: UDP</code></pre>
</div>
</div>
</p>

DeirdreRodgers
<p>Try this example</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: ingress-allow-tcp only
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  ingress:
  - ports:
    - port: 80
      protocol: TCP
</code></pre>
<p>Other all traffic will get blocked. Only TCP will work</p>
<pre><code>policyTypes: [&quot;ingress&quot;] indicates that this policy enforces policies for the ingress traffic.

inress: [] empty rule set does not whitelist any traffic, therefore all ingress traffic is blocked.
</code></pre>
<p>Example : <a href="https://github.com/ahmetb/kubernetes-network-policy-recipes/blob/master/11-deny-egress-traffic-from-an-application.md" rel="nofollow noreferrer">https://github.com/ahmetb/kubernetes-network-policy-recipes/blob/master/11-deny-egress-traffic-from-an-application.md</a></p>
