You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## `MatchLabelKeys` - Enhanced scheduling for versatile rolling updates
30
+
## `matchLabelKeys` - Enhanced scheduling for versatile rolling updates
29
31
30
-
During a workload's (e.g., Deployment) rolling update, a cluster may have Pods from multiple versions at the same time.
31
-
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.
32
+
During a workload's (e.g., Deployment) rolling update, a cluster may have Pods from multiple versions at the same time.
33
+
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.
The above matchLabelKeys will be translated in Pods like:
88
+
The above `matchLabelKeys` will be translated in Pods like:
87
89
-->
88
90
上述 Pod 中的 `matchLabelKeys` 将被转换为:
89
91
@@ -116,29 +118,29 @@ metadata:
116
118
```
117
119
118
120
<!--
119
-
## `MismatchLabelKeys` - Service isolation
121
+
## `mismatchLabelKeys` - Service isolation
120
122
121
-
`MismatchLabelKeys`is a set of Pod label keys, like `MatchLabelKeys`,
122
-
which looks up the values of these keys from the new Pod's labels, and merge them with `LabelSelector` as `key notin (value)`
123
-
so that PodAffinity does _not_ match Pods that have the same key-value in labels.
123
+
`mismatchLabelKeys`is a set of Pod label keys, like `matchLabelKeys`,
124
+
which looks up the values of these keys from the new Pod's labels, and merge them with `labelSelector` as `key notin (value)`
125
+
so that `podAffinity` does _not_ match Pods that have the same key-value in labels.
124
126
125
127
Suppose all Pods for each tenant get `tenant` label via a controller or a manifest management tool like Helm.
126
128
-->
127
129
## `mismatchLabelKeys` - 服务隔离
128
130
129
131
`mismatchLabelKeys`是一组 Pod 标签键,类似于 `matchLabelKeys`,
130
132
它在新 Pod 的标签中查找这些键的值,并将其与 `labelSelector` 合并为 `key notin (value)`,
131
-
以便 podAffinity **不**会匹配到具有相同标签键值的 Pod。
133
+
以便 `podAffinity` **不**会匹配到具有相同标签键值的 Pod。
132
134
133
135
假设每个租户的所有 Pod 通过控制器或像 Helm 这样的清单管理工具得到 `tenant` 标签。
134
136
135
137
<!--
136
-
Although the value of `tenant` label is unknown when composing each workload's manifest,
138
+
Although the value of `tenant` label is unknown when composing each workload's manifest,
137
139
the cluster admin wants to achieve exclusive 1:1 tenant to domain placement for a tenant isolation.
138
140
139
-
`MismatchLabelKeys`works for this usecase;
140
-
By applying the following affinity globally using a mutating webhook,
141
-
the cluster admin can ensure that the Pods from the same tenant will land on the same domain exclusively,
141
+
`mismatchLabelKeys`works for this usecase;
142
+
By applying the following affinity globally using a mutating webhook,
143
+
the cluster admin can ensure that the Pods from the same tenant will land on the same domain exclusively,
142
144
meaning Pods from other tenants won't land on the same domain.
143
145
-->
144
146
尽管在组合每个工作负载的清单时,`tenant` 标签的值是未知的,
@@ -150,8 +152,23 @@ meaning Pods from other tenants won't land on the same domain.
150
152
这意味着来自其他租户的 Pod 不会落到同一域上。
151
153
152
154
<!--
153
-
# ensures the pods of this tenant land on the same node pool
154
-
# ensures only Pods from this tenant lands on the same node pool
155
+
```yaml
156
+
affinity:
157
+
podAffinity: # ensures the pods of this tenant land on the same node pool
158
+
requiredDuringSchedulingIgnoredDuringExecution:
159
+
- matchLabelKeys:
160
+
- tenant
161
+
topologyKey: node-pool
162
+
podAntiAffinity: # ensures only Pods from this tenant lands on the same node pool
163
+
requiredDuringSchedulingIgnoredDuringExecution:
164
+
- mismatchLabelKeys:
165
+
- tenant
166
+
labelSelector:
167
+
matchExpressions:
168
+
- key: tenant
169
+
operator: Exists
170
+
topologyKey: node-pool
171
+
```
155
172
-->
156
173
```yaml
157
174
affinity:
@@ -172,13 +189,44 @@ affinity:
172
189
```
173
190
174
191
<!--
175
-
The above matchLabelKeys and mismatchLabelKeys will be translated to like:
192
+
The above `matchLabelKeys` and `mismatchLabelKeys` will be translated to like:
176
193
-->
177
194
上述的 `matchLabelKeys` 和 `mismatchLabelKeys` 将被转换为:
178
195
179
196
<!--
180
-
# ensures the pods of this tenant land on the same node pool
181
-
# ensures only Pods from this tenant lands on the same node pool
197
+
```yaml
198
+
kind: Pod
199
+
metadata:
200
+
name: application-server
201
+
labels:
202
+
tenant: service-a
203
+
spec:
204
+
affinity:
205
+
podAffinity: # ensures the pods of this tenant land on the same node pool
206
+
requiredDuringSchedulingIgnoredDuringExecution:
207
+
- matchLabelKeys:
208
+
- tenant
209
+
topologyKey: node-pool
210
+
labelSelector:
211
+
matchExpressions:
212
+
- key: tenant
213
+
operator: In
214
+
values:
215
+
- service-a
216
+
podAntiAffinity: # ensures only Pods from this tenant lands on the same node pool
217
+
requiredDuringSchedulingIgnoredDuringExecution:
218
+
- mismatchLabelKeys:
219
+
- tenant
220
+
labelSelector:
221
+
matchExpressions:
222
+
- key: tenant
223
+
operator: Exists
224
+
- key: tenant
225
+
operator: NotIn
226
+
values:
227
+
- service-a
228
+
topologyKey: node-pool
229
+
```
182
230
-->
183
231
```yaml
184
232
kind: Pod
@@ -215,7 +263,7 @@ spec:
215
263
```
216
264
217
265
<!--
218
-
## Getting involved
266
+
## Getting involved
219
267
220
268
These features are managed by Kubernetes [SIG Scheduling](https://github.com/kubernetes/community/tree/master/sig-scheduling).
221
269
@@ -229,10 +277,10 @@ Please join us and share your feedback. We look forward to hearing from you!
229
277
请加入我们并分享你的反馈。我们期待听到你的声音!
230
278
231
279
<!--
232
-
## How can I learn more?
280
+
## How can I learn more?
233
281
234
-
- [The official document of PodAffinity](/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity)
235
-
- [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)
282
+
- [The official document of podAffinity](/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity)
283
+
- [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