Skip to content

Commit f66fca6

Browse files
authored
Merge pull request #63236 from jab-rh/fixup-netpol-yaml
Fix YAML indentation for network policy optimization
2 parents 64284c3 + 0790613 commit f66fca6

File tree

1 file changed

+47
-41
lines changed

1 file changed

+47
-41
lines changed

modules/nw-networkpolicy-optimize-ovn.adoc

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// * networking/network_policy/about-network-policy.adoc
44

55
[id="nw-networkpolicy-optimize-ovn_{context}"]
6-
= Optimizations for network policy with OpenShift OVN
6+
= Optimizations for network policy with OVN-Kubernetes network plugin
77

88
When designing your network policy, refer to the following guidelines:
99

10-
* For network policies with the same `spec.podSelector` spec, it is more efficient to use one network policy with multiple `ingress` or `egress` rules, than multiple network policies with subsets of `ingress` or `egress` rules.
10+
* For network policies with the same `spec.podSelector` spec, it is more efficient to use one network policy with multiple `ingress` or `egress` rules, than multiple network policies with subsets of `ingress` or `egress` rules.
1111

1212
* Every `ingress` or `egress` rule based on the `podSelector` or `namespaceSelector` spec generates the number of OVS flows proportional to `number of pods selected by network policy + number of pods selected by ingress or egress rule`. Therefore, it is preferable to use the `podSelector` or `namespaceSelector` spec that can select as many pods as you need in one rule, instead of creating individual rules for every pod.
1313
+
@@ -18,18 +18,18 @@ For example, the following policy contains two rules:
1818
apiVersion: networking.k8s.io/v1
1919
kind: NetworkPolicy
2020
metadata:
21-
name: test-network-policy
21+
name: test-network-policy
2222
spec:
2323
podSelector: {}
2424
ingress:
25-
- from:
26-
- podSelector:
27-
matchLabels:
28-
role: frontend
29-
- from:
30-
- podSelector:
31-
matchLabels:
32-
role: backend
25+
- from:
26+
- podSelector:
27+
matchLabels:
28+
role: frontend
29+
- from:
30+
- podSelector:
31+
matchLabels:
32+
role: backend
3333
----
3434
+
3535
The following policy expresses those same two rules as one:
@@ -39,60 +39,66 @@ The following policy expresses those same two rules as one:
3939
apiVersion: networking.k8s.io/v1
4040
kind: NetworkPolicy
4141
metadata:
42-
name: test-network-policy
42+
name: test-network-policy
4343
spec:
4444
podSelector: {}
4545
ingress:
46-
- from:
47-
- podSelector:
48-
matchExpressions:
49-
- {key: role, operator: In, values: [frontend, backend]}
46+
- from:
47+
- podSelector:
48+
matchExpressions:
49+
- {key: role, operator: In, values: [frontend, backend]}
5050
----
5151
+
5252
The same guideline applies to the `spec.podSelector` spec. If you have the same `ingress` or `egress` rules for different network policies, it might be more efficient to create one network policy with a common `spec.podSelector` spec. For example, the following two policies have different rules:
5353
+
5454
[source,yaml]
5555
----
56+
apiVersion: networking.k8s.io/v1
57+
kind: NetworkPolicy
5658
metadata:
57-
name: policy1
59+
name: policy1
5860
spec:
59-
podSelector:
60-
matchLabels:
61-
role: db
61+
podSelector:
62+
matchLabels:
63+
role: db
6264
ingress:
63-
- from:
64-
- podSelector:
65-
matchLabels:
66-
role: frontend
67-
65+
- from:
66+
- podSelector:
67+
matchLabels:
68+
role: frontend
69+
---
70+
apiVersion: networking.k8s.io/v1
71+
kind: NetworkPolicy
6872
metadata:
69-
name: policy2
73+
name: policy2
7074
spec:
71-
podSelector:
72-
matchLabels:
73-
role: client
75+
podSelector:
76+
matchLabels:
77+
role: client
7478
ingress:
75-
- from:
76-
- podSelector:
77-
matchLabels:
78-
role: frontend
79+
- from:
80+
- podSelector:
81+
matchLabels:
82+
role: frontend
7983
----
8084
+
8185
The following network policy expresses those same two rules as one:
8286
+
8387
[source,yaml]
8488
----
89+
apiVersion: networking.k8s.io/v1
90+
kind: NetworkPolicy
8591
metadata:
86-
name: policy3
92+
name: policy3
8793
spec:
88-
podSelector:
89-
matchExpressions:
90-
- {key: role, operator: In, values: [db, client]}
94+
podSelector:
95+
matchExpressions:
96+
- {key: role, operator: In, values: [db, client]}
9197
ingress:
92-
- from:
93-
- podSelector:
94-
matchLabels:
95-
role: frontend
98+
- from:
99+
- podSelector:
100+
matchLabels:
101+
role: frontend
96102
----
97103
+
98104
You can apply this optimization when only multiple selectors are expressed as one. In cases where selectors are based on different labels, it may not be possible to apply this optimization. In those cases, consider applying some new labels for network policy optimization specifically.

0 commit comments

Comments
 (0)