'How to set egress > ipBlock for multiple IPs and ports?

Here is a section of my network policy:

egress:
   -to:
     - ipBlock: 
         cidr: 10.0.0.0/32
     - ipBlock:
         cidr: 10.0.0.1/32
    ports:
     - protocol: TCP
       port: 5978

I have a doubt whether these IPs will be allowed to connect to the same port.

Basically, if we want to have a different port for a different IP, what can we do?



Solution 1:[1]

I assume the snippet you shared is a portion of a NetworkPolicy.

If so, you can have multiple entries in the egress field, like this for example:

egress:
  - to:
    - ipBlock: 
        cidr: 10.0.0.1/32
    ports:
    - protocol: TCP
      port: 5978
  - to:
    - ipBlock: 
        cidr: 10.0.0.2/32
    ports:
    - protocol: TCP
      port: 1234

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 whites11