|
36 | 36 | - [Rule enforcement based on priorities](#rule-enforcement-based-on-priorities) |
37 | 37 | - [Advanced peer selection mechanisms of Antrea-native Policies](#advanced-peer-selection-mechanisms-of-antrea-native-policies) |
38 | 38 | - [Selecting Namespace by Name](#selecting-namespace-by-name) |
39 | | - - [K8s clusters with version 1.21 and above](#k8s-clusters-with-version-121-and-above) |
40 | | - - [K8s clusters with version 1.20 and below](#k8s-clusters-with-version-120-and-below) |
41 | 39 | - [Selecting Pods in the same Namespace with Self](#selecting-pods-in-the-same-namespace-with-self) |
42 | 40 | - [Selecting Namespaces with the same label values using SameLabels](#selecting-namespaces-with-the-same-label-values-using-samelabels) |
43 | 41 | - [FQDN based filtering](#fqdn-based-filtering) |
@@ -1171,11 +1169,8 @@ workloads from Namespaces with the use of a label selector (i.e. `namespaceSelec |
1171 | 1169 | However, it is often desirable to be able to select Namespaces directly by their `name` |
1172 | 1170 | as opposed to using the `labels` associated with the Namespaces. |
1173 | 1171 |
|
1174 | | -#### K8s clusters with version 1.21 and above |
1175 | | - |
1176 | | -Starting with K8s v1.21, all Namespaces are labeled with the `kubernetes.io/metadata.name: <namespaceName>` |
1177 | | -[label](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#automatic-labelling) |
1178 | | -provided that the `NamespaceDefaultLabelName` feature gate (enabled by default) is not disabled in K8s. |
| 1172 | +Namespaces are labeled with the `kubernetes.io/metadata.name: <namespaceName>` |
| 1173 | +[label](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#automatic-labelling). |
1179 | 1174 | K8s NetworkPolicy and Antrea-native policy users can take advantage of this reserved label |
1180 | 1175 | to select Namespaces directly by their `name` in `namespaceSelectors` as follows: |
1181 | 1176 |
|
@@ -1207,83 +1202,8 @@ spec: |
1207 | 1202 | name: AllowToCoreDNS |
1208 | 1203 | ``` |
1209 | 1204 |
|
1210 | | -**Note**: `NamespaceDefaultLabelName` feature gate is scheduled to be removed in K8s v1.24, thereby |
1211 | | -ensuring that labeling Namespaces by their name cannot be disabled. |
1212 | | - |
1213 | | -#### K8s clusters with version 1.20 and below |
1214 | | - |
1215 | | -In order to select Namespaces by name, Antrea labels Namespaces with a reserved label `antrea.io/metadata.name`, |
1216 | | -whose value is set to the Namespace's name. Users can then use this label in the |
1217 | | -`namespaceSelector` field, in both K8s NetworkPolicies and Antrea-native policies to |
1218 | | -select Namespaces by name. By default, Namespaces are not labeled with the reserved name label. |
1219 | | -In order for the Antrea controller to label the Namespaces, the `labelsmutator.antrea.io` |
1220 | | -`MutatingWebhookConfiguration` must be enabled. This can be done by applying the following |
1221 | | -webhook configuration YAML: |
1222 | | - |
1223 | | -```yaml |
1224 | | -apiVersion: admissionregistration.k8s.io/v1 |
1225 | | -kind: MutatingWebhookConfiguration |
1226 | | -metadata: |
1227 | | - # Do not edit this name. |
1228 | | - name: "labelsmutator.antrea.io" |
1229 | | - # Do not remove these labels. |
1230 | | - labels: |
1231 | | - app: antrea |
1232 | | - served-by: antrea-controller |
1233 | | -webhooks: |
1234 | | - - name: "namelabelmutator.antrea.io" |
1235 | | - clientConfig: |
1236 | | - service: |
1237 | | - name: "antrea" |
1238 | | - namespace: "kube-system" |
1239 | | - path: "/mutate/namespace" |
1240 | | - rules: |
1241 | | - - operations: ["CREATE", "UPDATE"] |
1242 | | - apiGroups: [""] |
1243 | | - apiVersions: ["v1"] |
1244 | | - resources: ["namespaces"] |
1245 | | - scope: "Cluster" |
1246 | | - admissionReviewVersions: ["v1", "v1beta1"] |
1247 | | - sideEffects: None |
1248 | | - timeoutSeconds: 5 |
1249 | | -``` |
1250 | | - |
1251 | | -**Note**: `antrea-controller` Pod must be restarted after applying this YAML. |
1252 | | - |
1253 | | -Once the webhook is configured, Antrea will start labeling all new and updated |
1254 | | -Namespaces with the `antrea.io/metadata.name: <namespaceName>` label. Users may now |
1255 | | -use this reserved label to select Namespaces by name as follows: |
1256 | | - |
1257 | | -```yaml |
1258 | | -apiVersion: crd.antrea.io/v1beta1 |
1259 | | -kind: NetworkPolicy |
1260 | | -metadata: |
1261 | | - name: test-annp-by-name |
1262 | | - namespace: default |
1263 | | -spec: |
1264 | | - priority: 5 |
1265 | | - tier: application |
1266 | | - appliedTo: |
1267 | | - - podSelector: {} |
1268 | | - egress: |
1269 | | - - action: Allow |
1270 | | - to: |
1271 | | - - podSelector: |
1272 | | - matchLabels: |
1273 | | - k8s-app: kube-dns |
1274 | | - namespaceSelector: |
1275 | | - matchLabels: |
1276 | | - antrea.io/metadata.name: kube-system |
1277 | | - ports: |
1278 | | - - protocol: TCP |
1279 | | - port: 53 |
1280 | | - - protocol: UDP |
1281 | | - port: 53 |
1282 | | - name: AllowToCoreDNS |
1283 | | -``` |
1284 | | - |
1285 | 1205 | The above example allows all Pods from Namespace "default" to connect to all "kube-dns" |
1286 | | -Pods from Namespace "kube-system" on TCP port 53. |
| 1206 | +Pods from Namespace "kube-system" on TCP port 53 and UDP port 53. |
1287 | 1207 |
|
1288 | 1208 | ### Selecting Pods in the same Namespace with Self |
1289 | 1209 |
|
|
0 commit comments