<p>I have an egress <code>NetPol</code> -&gt;</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: pod-egress-to-auth-endpoint
spec:
  podSelector:
    matchLabels:
      name: pod-a
  policyTypes:
  - Egress
  egress:
  - to:
    - ipBlock:
        cidr: 0.0.0.0/0 ## need to replace this with set of IP addresses allowed
    ports:
    - protocol: TCP
      port: 443
</code></pre>
<p>Now , instead of keeping the pod open to all the IPs (cidr -&gt; 0.0.0.0/0) , I want to restrict it to a set of IPs which will be coming from this url -</p>
<p><a href="https://ip-ranges.amazonaws.com/ip-ranges.json" rel="nofollow noreferrer">https://ip-ranges.amazonaws.com/ip-ranges.json</a></p>
<p>Desired NetPol -&gt;</p>
<pre><code> egress:
  - to:
    - ipBlock:
        cidr: x.x.x.x/x 
    - ipBlock:
        cidr: x.x.x.x/x 
    - ipBlock:
        cidr: x.x.x.x/x 
</code></pre>
<p>So , Is there a way I can achieve this , read all thes IPs from a file , add them in the <code>NetworkPolicy</code> here programmatically ? i.e If we have 5 Ips , create 5 ipBlocks in NetPol.</p>
<p>Is it feasible to do so ?</p>

devcodes
<p>replace <strong>x.x.x.x/x</strong> with the list of IPs from the URL below</p>
<pre><code> egress:
  - to:
    - ipBlock:
        cidr: x.x.x.x/x 
    - ipBlock:
        cidr: x.x.x.x/x 
    - ipBlock:
        cidr: x.x.x.x/x 
</code></pre>
