From e752b37bf03b5c0798e42db74933fd945b1ac82f Mon Sep 17 00:00:00 2001 From: Aldo Culquicondor <1299064+alculquicondor@users.noreply.github.com> Date: Mon, 16 Mar 2020 10:58:43 -0400 Subject: [PATCH] Default Topology Spread constraints (#19170) * Add usage of default constraints for Pod Topology Spread. Signed-off-by: Aldo Culquicondor * Add apiVersion and kind Signed-off-by: Aldo Culquicondor --- .../pods/pod-topology-spread-constraints.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/content/en/docs/concepts/workloads/pods/pod-topology-spread-constraints.md b/content/en/docs/concepts/workloads/pods/pod-topology-spread-constraints.md index 2f269255f4..35a373473b 100644 --- a/content/en/docs/concepts/workloads/pods/pod-topology-spread-constraints.md +++ b/content/en/docs/concepts/workloads/pods/pod-topology-spread-constraints.md @@ -182,6 +182,46 @@ There are some implicit conventions worth noting here: and you know that "zoneC" must be excluded. In this case, you can compose the yaml as below, so that "mypod" will be placed onto "zoneB" instead of "zoneC". Similarly `spec.nodeSelector` is also respected. {{< codenew file="pods/topology-spread-constraints/one-constraint-with-nodeaffinity.yaml" >}} + +### Cluster-level default constraints + +{{< feature-state for_k8s_version="v1.18" state="alpha" >}} + +It is possible to set default topology spread constraints for a cluster. Default +topology spread constraints are applied to a Pod if, and only if: + +- It doesn't define any constraints in its `.spec.topologySpreadConstraints`. +- It belongs to a service, replication controller, replica set or stateful set. + +Default constraints can be set as part of the `PodTopologySpread` plugin args +in a [scheduling profile](/docs/reference/scheduling/profiles). +The constraints are specified with the same [API above](#api), except that +`labelSelector` must be empty. The selectors are calculated from the services, +replication controllers, replica sets or stateful sets that the Pod belongs to. + +An example configuration might look like follows: + +```yaml +apiVersion: kubescheduler.config.k8s.io/v1alpha2 +kind: KubeSchedulerConfiguration + +profiles: + pluginConfig: + - name: PodTopologySpread + args: + defaultConstraints: + - maxSkew: 1 + topologyKey: failure-domain.beta.kubernetes.io/zone + whenUnsatisfiable: ScheduleAnyway +``` + +{{< note >}} +The score produced by default scheduling constraints might conflict with the +score produced by the +[`DefaultPodTopologySpread` plugin](/docs/reference/scheduling/profiles/#scheduling-plugins). +It is recommended that you disable this plugin in the scheduling profile when +using default constraints for `PodTopologySpread`. +{{< /note >}} ## Comparison with PodAffinity/PodAntiAffinity