|
2 | 2 | //
|
3 | 3 | // * nodes/scheduling/nodes-scheduler-pod-topology-spread-constraints
|
4 | 4 |
|
| 5 | +:_mod-docs-content-type: REFERENCE |
5 | 6 | [id="nodes-scheduler-pod-topology-spread-constraints-examples_{context}"]
|
6 |
| -= Example pod topology spread constraints |
| 7 | += Example configurations for pod topology spread constraints |
7 | 8 |
|
8 |
| -The following examples demonstrate pod topology spread constraint configurations. |
9 |
| - |
10 |
| -[id="nodes-scheduler-pod-topology-spread-constraints-example-single_{context}"] |
11 |
| -== Single pod topology spread constraint example |
| 9 | +You can specify which pods to group together, which topology domains they are spread among, and the acceptable skew. |
12 | 10 |
|
13 |
| -// TODO: Add a diagram? |
| 11 | +The following examples demonstrate pod topology spread constraint configurations. |
14 | 12 |
|
15 |
| -This example `Pod` spec defines one pod topology spread constraint. It matches on pods labeled `region: us-east`, distributes among zones, specifies a skew of `1`, and does not schedule the pod if it does not meet these requirements. |
| 13 | +.Example to distribute pods that match the specified labels based on their zone |
| 14 | +[source,yaml] |
| 15 | +---- |
| 16 | +apiVersion: v1 |
| 17 | +kind: Pod |
| 18 | +metadata: |
| 19 | + name: my-pod |
| 20 | + labels: |
| 21 | + region: us-east |
| 22 | +spec: |
| 23 | + securityContext: |
| 24 | + runAsNonRoot: true |
| 25 | + seccompProfile: |
| 26 | + type: RuntimeDefault |
| 27 | + topologySpreadConstraints: |
| 28 | + - maxSkew: 1 <1> |
| 29 | + topologyKey: topology.kubernetes.io/zone <2> |
| 30 | + whenUnsatisfiable: DoNotSchedule <3> |
| 31 | + labelSelector: <4> |
| 32 | + matchLabels: |
| 33 | + region: us-east <5> |
| 34 | + matchLabelKeys: |
| 35 | + - my-pod-label <6> |
| 36 | + containers: |
| 37 | + - image: "docker.io/ocpqe/hello-pod" |
| 38 | + name: hello-pod |
| 39 | + securityContext: |
| 40 | + allowPrivilegeEscalation: false |
| 41 | + capabilities: |
| 42 | + drop: [ALL] |
| 43 | +---- |
| 44 | +<1> The maximum difference in number of pods between any two topology domains. The default is `1`, and you cannot specify a value of `0`. |
| 45 | +<2> The key of a node label. Nodes with this key and identical value are considered to be in the same topology. |
| 46 | +<3> How to handle a pod if it does not satisfy the spread constraint. The default is `DoNotSchedule`, which tells the scheduler not to schedule the pod. Set to `ScheduleAnyway` to still schedule the pod, but the scheduler prioritizes honoring the skew to not make the cluster more imbalanced. |
| 47 | +<4> Pods that match this label selector are counted and recognized as a group when spreading to satisfy the constraint. Be sure to specify a label selector, otherwise no pods can be matched. |
| 48 | +<5> Be sure that this `Pod` spec also sets its labels to match this label selector if you want it to be counted properly in the future. |
| 49 | +<6> A list of pod label keys to select which pods to calculate spreading over. |
16 | 50 |
|
| 51 | +.Example demonstrating a single pod topology spread constraint |
17 | 52 | [source,yaml]
|
18 | 53 | ----
|
19 | 54 | kind: Pod
|
|
43 | 78 | drop: [ALL]
|
44 | 79 | ----
|
45 | 80 |
|
46 |
| -[id="nodes-scheduler-pod-topology-spread-constraints-example-multiple_{context}"] |
47 |
| -== Multiple pod topology spread constraints example |
48 |
| - |
49 |
| -// TODO: Add a diagram? |
50 |
| - |
51 |
| -This example `Pod` spec defines two pod topology spread constraints. Both match on pods labeled `region: us-east`, specify a skew of `1`, and do not schedule the pod if it does not meet these requirements. |
52 |
| - |
53 |
| -The first constraint distributes pods based on a user-defined label `node`, and the second constraint distributes pods based on a user-defined label `rack`. Both constraints must be met for the pod to be scheduled. |
| 81 | +The previous example defines a `Pod` spec with a one pod topology spread constraint. It matches on pods labeled `region: us-east`, distributes among zones, specifies a skew of `1`, and does not schedule the pod if it does not meet these requirements. |
54 | 82 |
|
| 83 | +.Example demonstrating multiple pod topology spread constraints |
55 | 84 | [source,yaml]
|
56 | 85 | ----
|
57 | 86 | kind: Pod
|
|
86 | 115 | capabilities:
|
87 | 116 | drop: [ALL]
|
88 | 117 | ----
|
| 118 | + |
| 119 | +The previous example defines a `Pod` spec with two pod topology spread constraints. Both match on pods labeled `region: us-east`, specify a skew of `1`, and do not schedule the pod if it does not meet these requirements. |
| 120 | + |
| 121 | +The first constraint distributes pods based on a user-defined label `node`, and the second constraint distributes pods based on a user-defined label `rack`. Both constraints must be met for the pod to be scheduled. |
0 commit comments