Skip to content

Commit 9557e72

Browse files
authored
Merge pull request #47753 from windsonsea/matche
Fix some typos in 2024-08-16-matchlabelkeys-podaffinity.md
2 parents acdde24 + 446d465 commit 9557e72

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

content/en/blog/_posts/2024-08-16-matchlabelkeys-podaffinity.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ author: >
77
Kensei Nakada (Tetrate)
88
---
99

10-
Kubernetes 1.29 introduced new fields `MatchLabelKeys` and `MismatchLabelKeys` in PodAffinity and PodAntiAffinity.
10+
Kubernetes 1.29 introduced new fields `matchLabelKeys` and `mismatchLabelKeys` in `podAffinity` and `podAntiAffinity`.
1111

1212
In Kubernetes 1.31, this feature moves to beta and the corresponding feature gate (`MatchLabelKeysInPodAffinity`) gets enabled by default.
1313

14-
## `MatchLabelKeys` - Enhanced scheduling for versatile rolling updates
14+
## `matchLabelKeys` - Enhanced scheduling for versatile rolling updates
1515

16-
During a workload's (e.g., Deployment) rolling update, a cluster may have Pods from multiple versions at the same time.
17-
However, the scheduler cannot distinguish between old and new versions based on the `LabelSelector` specified in PodAffinity or PodAntiAffinity. As a result, it will co-locate or disperse Pods regardless of their versions.
16+
During a workload's (e.g., Deployment) rolling update, a cluster may have Pods from multiple versions at the same time.
17+
However, the scheduler cannot distinguish between old and new versions based on the `labelSelector` specified in `podAffinity` or `podAntiAffinity`. As a result, it will co-locate or disperse Pods regardless of their versions.
1818

1919
This can lead to sub-optimal scheduling outcome, for example:
20-
- New version Pods are co-located with old version Pods (PodAffinity), which will eventually be removed after rolling updates.
21-
- Old version Pods are distributed across all available topologies, preventing new version Pods from finding nodes due to PodAntiAffinity.
20+
- New version Pods are co-located with old version Pods (`podAffinity`), which will eventually be removed after rolling updates.
21+
- Old version Pods are distributed across all available topologies, preventing new version Pods from finding nodes due to `podAntiAffinity`.
2222

23-
`MatchLabelKeys` is a set of Pod label keys and addresses this problem.
24-
The scheduler looks up the values of these keys from the new Pod's labels and combines them with `LabelSelector`
25-
so that PodAffinity matches Pods that have the same key-value in labels.
23+
`matchLabelKeys` is a set of Pod label keys and addresses this problem.
24+
The scheduler looks up the values of these keys from the new Pod's labels and combines them with `labelSelector`
25+
so that podAffinity matches Pods that have the same key-value in labels.
2626

27-
By using label [pod-template-hash](/docs/concepts/workloads/controllers/deployment/#pod-template-hash-label) in `MatchLabelKeys`,
28-
you can ensure that only Pods of the same version are evaluated for PodAffinity or PodAntiAffinity.
27+
By using label [pod-template-hash](/docs/concepts/workloads/controllers/deployment/#pod-template-hash-label) in `matchLabelKeys`,
28+
you can ensure that only Pods of the same version are evaluated for `podAffinity` or `podAntiAffinity`.
2929

3030
```yaml
3131
apiVersion: apps/v1
@@ -43,11 +43,11 @@ metadata:
4343
values:
4444
- database
4545
topologyKey: topology.kubernetes.io/zone
46-
matchLabelKeys:
46+
matchLabelKeys:
4747
- pod-template-hash
4848
```
4949
50-
The above matchLabelKeys will be translated in Pods like:
50+
The above `matchLabelKeys` will be translated in Pods like:
5151

5252
```yaml
5353
kind: Pod
@@ -68,26 +68,26 @@ metadata:
6868
- key: pod-template-hash # Added from matchLabelKeys; Only Pods from the same replicaset will match this affinity.
6969
operator: In
7070
values:
71-
- xyz
71+
- xyz
7272
topologyKey: topology.kubernetes.io/zone
73-
matchLabelKeys:
73+
matchLabelKeys:
7474
- pod-template-hash
7575
```
7676

77-
## `MismatchLabelKeys` - Service isolation
77+
## `mismatchLabelKeys` - Service isolation
7878

79-
`MismatchLabelKeys` is a set of Pod label keys, like `MatchLabelKeys`,
80-
which looks up the values of these keys from the new Pod's labels, and merge them with `LabelSelector` as `key notin (value)`
81-
so that PodAffinity does _not_ match Pods that have the same key-value in labels.
79+
`mismatchLabelKeys` is a set of Pod label keys, like `matchLabelKeys`,
80+
which looks up the values of these keys from the new Pod's labels, and merge them with `labelSelector` as `key notin (value)`
81+
so that `podAffinity` does _not_ match Pods that have the same key-value in labels.
8282

83-
Suppose all Pods for each tenant get `tenant` label via a controller or a manifest management tool like Helm.
83+
Suppose all Pods for each tenant get `tenant` label via a controller or a manifest management tool like Helm.
8484

85-
Although the value of `tenant` label is unknown when composing each workload's manifest,
85+
Although the value of `tenant` label is unknown when composing each workload's manifest,
8686
the cluster admin wants to achieve exclusive 1:1 tenant to domain placement for a tenant isolation.
8787

88-
`MismatchLabelKeys` works for this usecase;
89-
By applying the following affinity globally using a mutating webhook,
90-
the cluster admin can ensure that the Pods from the same tenant will land on the same domain exclusively,
88+
`mismatchLabelKeys` works for this usecase;
89+
By applying the following affinity globally using a mutating webhook,
90+
the cluster admin can ensure that the Pods from the same tenant will land on the same domain exclusively,
9191
meaning Pods from other tenants won't land on the same domain.
9292

9393
```yaml
@@ -108,7 +108,7 @@ affinity:
108108
topologyKey: node-pool
109109
```
110110

111-
The above matchLabelKeys and mismatchLabelKeys will be translated to like:
111+
The above `matchLabelKeys` and `mismatchLabelKeys` will be translated to like:
112112

113113
```yaml
114114
kind: Pod
@@ -140,17 +140,17 @@ spec:
140140
- key: tenant
141141
operator: NotIn
142142
values:
143-
- service-a
143+
- service-a
144144
topologyKey: node-pool
145145
```
146146

147-
## Getting involved
147+
## Getting involved
148148

149149
These features are managed by Kubernetes [SIG Scheduling](https://github.com/kubernetes/community/tree/master/sig-scheduling).
150150

151151
Please join us and share your feedback. We look forward to hearing from you!
152152

153-
## How can I learn more?
153+
## How can I learn more?
154154

155-
- [The official document of PodAffinity](/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity)
156-
- [KEP-3633: Introduce MatchLabelKeys and MismatchLabelKeys to PodAffinity and PodAntiAffinity](https://github.com/kubernetes/enhancements/blob/master/keps/sig-scheduling/3633-matchlabelkeys-to-podaffinity/README.md#story-2)
155+
- [The official document of podAffinity](/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity)
156+
- [KEP-3633: Introduce matchLabelKeys and mismatchLabelKeys to podAffinity and podAntiAffinity](https://github.com/kubernetes/enhancements/blob/master/keps/sig-scheduling/3633-matchlabelkeys-to-podaffinity/README.md#story-2)

0 commit comments

Comments
 (0)