Kubernetes Blog
Follow
Kubernetes 1.31: MatchLabelKeys in PodAffinity graduates to beta
Kubernetes 1.29 introduced MatchLabelKeys and MismatchLabelKeys in PodAffinity and PodAntiAffinity for enhanced scheduling during rolling updates. In Kubernetes 1.31, these features moved to beta with the MatchLabelKeysInPodAffinity feature gate enabled by default.MatchLabelKeys allows schedulers to distinguish between Pods of different versions during updates by matching labels, ensuring optimal co-location or dispersion of Pods. MismatchLabelKeys prevents Pods from the same tenant or service from landing on the same node pool, providing tenant isolation.To use MatchLabelKeys, specify label keys in the PodAffinity or PodAntiAffinity rule, and the scheduler will include those keys in the label matching. For example, using the pod-template-hash label ensures that only Pods of the same replicaset are evaluated for affinity.MismatchLabelKeys works similarly, but with a not-in operator to exclude Pods with matching label values. This is useful for tenant isolation, where Pods from different tenants should be placed on separate nodes.Both MatchLabelKeys and MismatchLabelKeys are managed by the Kubernetes SIG Scheduling and welcome feedback from users. Further details are available in the official PodAffinity documentation and KEP-3633.