You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
= Differences between multi-network policy and network policy
3
+
4
+
Although the `MultiNetworkPolicy` API implements the `NetworkPolicy` API, there are several important differences:
5
+
6
+
* You must use the `MultiNetworkPolicy` API:
7
+
+
8
+
[source,yaml]
9
+
----
10
+
apiVersion: k8s.cni.cncf.io/v1beta1
11
+
kind: MultiNetworkPolicy
12
+
----
13
+
14
+
* You must use the `multi-networkpolicy` resource name when using the CLI to interact with multi-network policies. For example, you can view a multi-network policy object with the `oc get multi-networkpolicy <name>` command where `<name>` is the name of a multi-network policy.
15
+
16
+
* You must specify an annotation with the name of the network attachment definition that defines the macvlan additional network:
17
+
+
18
+
[source,yaml]
19
+
----
20
+
apiVersion: k8s.cni.cncf.io/v1beta1
21
+
kind: MultiNetworkPolicy
22
+
metadata:
23
+
annotations:
24
+
k8s.v1.cni.cncf.io/policy-for: <network_name>
25
+
----
26
+
+
27
+
--
28
+
where:
29
+
30
+
`<network_name>`:: Specifies the name of a network attachment definition.
To define granular rules describing ingress or egress network traffic allowed for namespaces in your cluster, you can create a network policy.
20
+
To define granular rules describing ingress or egress network traffic allowed for namespaces in your cluster, you can create a {name} policy.
14
21
22
+
ifndef::multi[]
15
23
[NOTE]
16
24
====
17
25
If you log in with a user with the `cluster-admin` role, then you can create a network policy in any namespace in the cluster.
18
26
====
27
+
endif::multi[]
19
28
20
29
.Prerequisites
21
30
@@ -28,8 +37,11 @@ the OVN-Kubernetes network provider or the OpenShift SDN network provider with `
28
37
endif::ovn[]
29
38
This mode is the default for OpenShift SDN.
30
39
* You installed the OpenShift CLI (`oc`).
31
-
* You are logged in to the cluster with a user with `admin` privileges.
32
-
* You are working in the namespace that the network policy applies to.
40
+
* You are logged in to the cluster with a user with `{role}` privileges.
41
+
* You are working in the namespace that the {name} policy applies to.
42
+
ifndef::multi[]
43
+
* Your cluster is using a cluster network provider that supports `NetworkPolicy` objects, such as the OpenShift SDN network provider with `mode: NetworkPolicy` set. This mode is the default for OpenShift SDN.
44
+
endif::multi[]
33
45
34
46
.Procedure
35
47
@@ -44,39 +56,74 @@ $ touch <policy_name>.yaml
44
56
--
45
57
where:
46
58
47
-
`<policy_name>`:: Specifies the network policy file name.
59
+
`<policy_name>`:: Specifies the {name} policy file name.
48
60
--
49
61
50
-
.. Define a network policy in the file that you just created, such as in the following examples:
62
+
.. Define a {name} policy in the file that you just created, such as in the following examples:
51
63
+
52
64
.Deny ingress from all pods in all namespaces
53
65
[source,yaml]
54
66
----
67
+
ifndef::multi[]
55
68
kind: NetworkPolicy
56
69
apiVersion: networking.k8s.io/v1
70
+
endif::multi[]
71
+
ifdef::multi[]
72
+
apiVersion: k8s.cni.cncf.io/v1beta1
73
+
kind: MultiNetworkPolicy
74
+
endif::multi[]
57
75
metadata:
58
76
name: deny-by-default
77
+
ifdef::multi[]
78
+
annotations:
79
+
k8s.v1.cni.cncf.io/policy-for: <network_name>
80
+
endif::multi[]
59
81
spec:
60
82
podSelector:
61
83
ingress: []
62
84
----
85
+
ifdef::multi[]
86
+
+
87
+
--
88
+
where
89
+
90
+
`<network_name>`:: Specifies the name of a network attachment definition.
91
+
--
92
+
endif::multi[]
63
93
+
64
94
.Allow ingress from all pods in the same namespace
65
95
[source,yaml]
66
96
----
97
+
ifndef::multi[]
67
98
kind: NetworkPolicy
68
99
apiVersion: networking.k8s.io/v1
100
+
endif::multi[]
101
+
ifdef::multi[]
102
+
apiVersion: k8s.cni.cncf.io/v1beta1
103
+
kind: MultiNetworkPolicy
104
+
endif::multi[]
69
105
metadata:
70
106
name: allow-same-namespace
107
+
ifdef::multi[]
108
+
annotations:
109
+
k8s.v1.cni.cncf.io/policy-for: <network_name>
110
+
endif::multi[]
71
111
spec:
72
112
podSelector:
73
113
ingress:
74
114
- from:
75
115
- podSelector: {}
76
116
----
117
+
ifdef::multi[]
118
+
+
119
+
--
120
+
where
77
121
122
+
`<network_name>`:: Specifies the name of a network attachment definition.
123
+
--
124
+
endif::multi[]
78
125
79
-
. To create the network policy object, enter the following command:
126
+
. To create the {name} policy object, enter the following command:
0 commit comments