diff --git a/Framework/KubernetesWorkflow/K8sController.cs b/Framework/KubernetesWorkflow/K8sController.cs index 5eebb4bf..014f1f36 100644 --- a/Framework/KubernetesWorkflow/K8sController.cs +++ b/Framework/KubernetesWorkflow/K8sController.cs @@ -375,6 +375,7 @@ namespace KubernetesWorkflow PriorityClassName = GetPriorityClassName(containerRecipes), NodeSelector = CreateNodeSelector(location, containerRecipes), Tolerations = CreateTolerations(containerRecipes), + Affinity = CreateSpreadAffinity(), Containers = CreateDeploymentContainers(containerRecipes), Volumes = CreateVolumes(containerRecipes) } @@ -422,6 +423,34 @@ namespace KubernetesWorkflow }).ToList(); } + private V1Affinity CreateSpreadAffinity() + { + return new V1Affinity + { + PodAntiAffinity = new V1PodAntiAffinity + { + RequiredDuringSchedulingIgnoredDuringExecution = new List + { + new V1PodAffinityTerm + { + TopologyKey = "kubernetes.io/hostname", + LabelSelector = new V1LabelSelector + { + MatchExpressions = new List + { + new V1LabelSelectorRequirement + { + Key = PodLabelKey, + OperatorProperty = "Exists" + } + } + } + } + } + } + }; + } + private K8sNodeLabel? GetNodeLabelForLocation(ILocation location) { var l = (Location)location;