Skip to content

Commit 4dcb78c

Browse files
authored
Merge pull request #40008 from denkensk/update-match
doc: forbid to set matchLabelKeys when labelSelector isn’t set in topologySpreadConstraints
2 parents 9f76854 + 1378908 commit 4dcb78c

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

content/en/docs/concepts/scheduling-eviction/topology-spread-constraints.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,30 @@ your cluster. Those fields are:
129129
for more details.
130130

131131
- **matchLabelKeys** is a list of pod label keys to select the pods over which
132-
spreading will be calculated. The keys are used to lookup values from the pod labels, those key-value labels are ANDed with `labelSelector` to select the group of existing pods over which spreading will be calculated for the incoming pod. Keys that don't exist in the pod labels will be ignored. A null or empty list means only match against the `labelSelector`.
133-
134-
With `matchLabelKeys`, users don't need to update the `pod.spec` between different revisions. The controller/operator just needs to set different values to the same `label` key for different revisions. The scheduler will assume the values automatically based on `matchLabelKeys`. For example, if users use Deployment, they can use the label keyed with `pod-template-hash`, which is added automatically by the Deployment controller, to distinguish between different revisions in a single Deployment.
132+
spreading will be calculated. The keys are used to lookup values from the pod labels,
133+
those key-value labels are ANDed with `labelSelector` to select the group of existing
134+
pods over which spreading will be calculated for the incoming pod. The same key is
135+
forbidden to exist in both `matchLabelKeys` and `labelSelector`. `matchLabelKeys` cannot
136+
be set when `labelSelector` isn't set. Keys that don't exist in the pod labels will be
137+
ignored. A null or empty list means only match against the `labelSelector`.
138+
139+
With `matchLabelKeys`, you don't need to update the `pod.spec` between different revisions.
140+
The controller/operator just needs to set different values to the same label key for different
141+
revisions. The scheduler will assume the values automatically based on `matchLabelKeys`. For
142+
example, if you are configuring a Deployment, you can use the label keyed with
143+
[pod-template-hash](/docs/concepts/workloads/controllers/deployment/#pod-template-hash-label), which
144+
is added automatically by the Deployment controller, to distinguish between different revisions
145+
in a single Deployment.
135146

136147
```yaml
137148
topologySpreadConstraints:
138149
- maxSkew: 1
139150
topologyKey: kubernetes.io/hostname
140151
whenUnsatisfiable: DoNotSchedule
152+
labelSelector:
153+
matchLabels:
154+
app: foo
141155
matchLabelKeys:
142-
- app
143156
- pod-template-hash
144157
```
145158

0 commit comments

Comments
 (0)