@@ -189,6 +189,7 @@ Resources specified on the quota outside of the allowed set results in a validat
189
189
| ` BestEffort ` | Match pods that have best effort quality of service. |
190
190
| ` NotBestEffort ` | Match pods that do not have best effort quality of service. |
191
191
| ` PriorityClass ` | Match pods that references the specified [ priority class] ( /docs/concepts/configuration/pod-priority-preemption ) . |
192
+ | ` CrossNamespacePodAffinity ` | Match pods that have cross-namespace pod [ (anti)affinity terms] ( /docs/concepts/scheduling-eviction/assign-pod-node ) . |
192
193
193
194
The ` BestEffort ` scope restricts a quota to tracking the following resource:
194
195
@@ -429,6 +430,63 @@ memory 0 20Gi
429
430
pods 0 10
430
431
```
431
432
433
+ ### Cross-namespace Pod Affinity Quota
434
+
435
+ {{< feature-state for_k8s_version="v1.21" state="alpha" >}}
436
+
437
+ Operators can use `CrossNamespacePodAffinity` quota scope to limit which namespaces are allowed to
438
+ have pods with affinity terms that cross namespaces. Specifically, it controls which pods are allowed
439
+ to set `namespaces` or `namespaceSelector` fields in pod affinity terms.
440
+
441
+ Preventing users from using cross-namespace affinity terms might be desired since a pod
442
+ with anti-affinity constraints can block pods from all other namespaces
443
+ from getting scheduled in a failure domain.
444
+
445
+ Using this scope operators can prevent certain namespaces (`foo-ns` in the example below)
446
+ from having pods that use cross-namespace pod affinity by creating a resource quota object in
447
+ that namespace with `CrossNamespaceAffinity` scope and hard limit of 0:
448
+
449
+ ```yaml
450
+ apiVersion: v1
451
+ kind: ResourceQuota
452
+ metadata:
453
+ name: disable-cross-namespace-affinity
454
+ namespace: foo-ns
455
+ spec:
456
+ hard:
457
+ pods: "0"
458
+ scopeSelector:
459
+ matchExpressions:
460
+ - scopeName: CrossNamespaceAffinity
461
+ ```
462
+
463
+ If operators want to disallow using ` namespaces ` and ` namespaceSelector ` by default, and
464
+ only allow it for specific namespaces, they could configure ` CrossNamespaceAffinity `
465
+ as a limited resource by setting the kube-apiserver flag --admission-control-config-file
466
+ to the path of the following configuration file:
467
+
468
+ ``` yaml
469
+ apiVersion : apiserver.config.k8s.io/v1
470
+ kind : AdmissionConfiguration
471
+ plugins :
472
+ - name : " ResourceQuota"
473
+ configuration :
474
+ apiVersion : apiserver.config.k8s.io/v1
475
+ kind : ResourceQuotaConfiguration
476
+ limitedResources :
477
+ - resource : pods
478
+ matchScopes :
479
+ - scopeName : CrossNamespaceAffinity
480
+ ` ` `
481
+
482
+ With the above configuration, pods can use ` namespaces` and `namespaceSelector` in pod affinity only
483
+ if the namespace where they are created have a resource quota object with
484
+ ` CrossNamespaceAffinity` scope and a hard limit greater than or equal to the number of pods using those fields.
485
+
486
+ This feature is alpha and disabled by default. You can enable it by setting the
487
+ [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
488
+ ` PodAffinityNamespaceSelector` in both kube-apiserver and kube-scheduler.
489
+
432
490
# # Requests compared to Limits {#requests-vs-limits}
433
491
434
492
When allocating compute resources, each container may specify a request and a limit value for either CPU or memory.
0 commit comments