From 2d10b14366cb1bd1b9b1d51ad8e372bef55fccf3 Mon Sep 17 00:00:00 2001 From: mamutmk5 <3045922+mamutmk5@users.noreply.github.com> Date: Thu, 30 Nov 2023 12:18:54 +0100 Subject: [PATCH 1/4] BC-5423 - add pod affinity ruls to deployment --- .../templates/deployment.yml.j2 | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 b/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 index 88e83c5..3fae93d 100644 --- a/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 +++ b/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 @@ -62,3 +62,36 @@ spec: requests: cpu: {{ SHD_CPU_REQUESTS|default("100m", true) }} memory: {{ SHD_MEMORY_REQUESTS|default("128Mi", true) }} + affinity: + podAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: app.kubernetes.io/part-of + operator: In + values: + - schulcloud-verbund + topologyKey: "kubernetes.io/hostname" + namespaceSelector: {} + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 10 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: app.kubernetes.io/name + operator: In + values: + - shd + topologyKey: "cloud.ionos.com/nodepool-name" + - weight: 10 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: app.kubernetes.io/name + operator: In + values: + - shd + topologyKey: "topology.kubernetes.io/zone" From 2011fb5956aa4be66a000b962ba67dd173501b11 Mon Sep 17 00:00:00 2001 From: mamutmk5 <3045922+mamutmk5@users.noreply.github.com> Date: Thu, 30 Nov 2023 15:52:17 +0100 Subject: [PATCH 2/4] BC-5423 - Adjusted weighting for pod Inter-pod affinity and anti-affinity --- ansible/roles/superhero-dashboard/templates/deployment.yml.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 b/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 index 3fae93d..3954a9b 100644 --- a/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 +++ b/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 @@ -65,7 +65,7 @@ spec: affinity: podAffinity: preferredDuringSchedulingIgnoredDuringExecution: - - weight: 100 + - weight: 9 podAffinityTerm: labelSelector: matchExpressions: @@ -86,7 +86,7 @@ spec: values: - shd topologyKey: "cloud.ionos.com/nodepool-name" - - weight: 10 + - weight: 20 podAffinityTerm: labelSelector: matchExpressions: From e85a005ef1beecfafb73ea1d03c112e9f9185083 Mon Sep 17 00:00:00 2001 From: mamutmk5 <3045922+mamutmk5@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:52:55 +0100 Subject: [PATCH 3/4] BC-5423 - Make pod anti affinity rule configurable and optional --- ansible/roles/superhero-dashboard/templates/deployment.yml.j2 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 b/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 index 3954a9b..956ddb0 100644 --- a/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 +++ b/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 @@ -77,6 +77,7 @@ spec: namespaceSelector: {} podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: +{% if ANIT_AFFINITY_NODEPOOL_ENABLE is defined and ANIT_AFFINITY_NODEPOOL_ENABLE|bool %} - weight: 10 podAffinityTerm: labelSelector: @@ -85,7 +86,8 @@ spec: operator: In values: - shd - topologyKey: "cloud.ionos.com/nodepool-name" + topologyKey: {{ ANIT_AFFINITY_NODEPOOL_TOPOLOGY_KEY }} +{% endif %} - weight: 20 podAffinityTerm: labelSelector: From a4310dd928eda375c84c7e5ca5f55a42c8f1da97 Mon Sep 17 00:00:00 2001 From: mamutmk5 <3045922+mamutmk5@users.noreply.github.com> Date: Mon, 4 Dec 2023 12:44:23 +0100 Subject: [PATCH 4/4] BC-5423 - make affinity rules optional --- ansible/roles/superhero-dashboard/templates/deployment.yml.j2 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 b/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 index 956ddb0..46fde78 100644 --- a/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 +++ b/ansible/roles/superhero-dashboard/templates/deployment.yml.j2 @@ -62,6 +62,7 @@ spec: requests: cpu: {{ SHD_CPU_REQUESTS|default("100m", true) }} memory: {{ SHD_MEMORY_REQUESTS|default("128Mi", true) }} +{% if AFFINITY_ENABLE is defined and AFFINITY_ENABLE|bool %} affinity: podAffinity: preferredDuringSchedulingIgnoredDuringExecution: @@ -97,3 +98,4 @@ spec: values: - shd topologyKey: "topology.kubernetes.io/zone" +{% endif %}