Kubernetes supports namespaceSelector in podAntiAffinity configuration:
Namespace selector
FEATURE STATE: Kubernetes v1.24 [stable]
You can also select matching namespaces using namespaceSelector, which is a label query over the set of namespaces. The affinity term is applied to namespaces selected by both namespaceSelector and the namespaces field. Note that an empty namespaceSelector ({}) matches all namespaces, while a null or empty namespaces list and null namespaceSelector matches the namespace of the Pod where the rule is defined.
This configuration allows matching labels across namespaces which is useful in some namespace layouts.
Potential Terraform Configuration
pod_anti_affinity {
required_during_scheduling_ignored_during_execution {
topology_key = "kubernetes.io/hostname"
label_selector {
match_labels = {
"mylabel" : "mylabelvalue"
}
}
# Proposed form for all namespaces:
namespace_selector {}
# Proposed form for specific namespaces:
namespace_selector {
match_labels = {
"mynamespacelabel" = "excludethis"
}
}
}
}
Description
Kubernetes supports namespaceSelector in podAntiAffinity configuration:
This configuration allows matching labels across namespaces which is useful in some namespace layouts.
Potential Terraform Configuration
References
https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#namespace-selector
Community Note