Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are multiple network policies rules processed logically as "and" rules or "or"?

In the basic example of the documentation for declaring a network policy: https://kubernetes.io/docs/concepts/services-networking/network-policies/#the-networkpolicy-resource

So this sets several rules, as per the documentation:

So, the example NetworkPolicy:

- isolates “role=db” pods in the “default” namespace for both ingress
and egress traffic (if they weren’t already isolated)
- allows connections to TCP port 6379 of “role=db” pods in the “default”
namespace from any pod in the “default” namespace with the
label “role=frontend”
- allows connections to TCP port 6379 of “role=db” pods
in the “default” namespace from any pod in a namespace with
the label “project=myproject”
...

Does this means that the pods of "role=db" label can receive connections from:

  • other pods with labels “role=frontend” AND namespace with label “project=myproject”; or
  • other pods with labels “role=frontend” OR namespace with label “project=myproject”.

Thanks!

like image 686
testTester Avatar asked Mar 06 '18 04:03

testTester


People also ask

What rule can be defined for a network policy?

Network policies can be viewed as rules. Each rule has a set of conditions and settings. NPS compares the conditions of the rule to the properties of connection requests. If a match occurs between the rule and the connection request, the settings defined in the rule are applied to the connection.

Are Kubernetes network policies stateful?

NetworkPolicy is stateful and will allow an established connection to communicate both ways.

What is network policy in Kubernetes?

If you want to control traffic flow at the IP address or port level (OSI layer 3 or 4), NetworkPolicies allow you to specify rules for traffic flow within your cluster, and also between Pods and the outside world. Your cluster must use a network plugin that supports NetworkPolicy enforcement.

Does canal support network policy?

Canal. If you want to use Flannel for networking but you need to define some network policies, yo can do it with Canal. The Canal means you're using Calico for policy and flannel for networking. For more details check Project Calico documentation.


1 Answers

The kubernetes network recipe "ALLOW traffic from apps using multiple selectors" is clear:

  • Rules specified in spec.ingress.from are OR'ed.
  • This means the pods selected by the selectors are combined are whitelisted altogether.
like image 158
VonC Avatar answered Nov 14 '22 16:11

VonC