From 8d3738004da5e60793f32f42d5a500d60225fa66 Mon Sep 17 00:00:00 2001 From: mamutmk5 <3045922+mamutmk5@users.noreply.github.com> Date: Thu, 30 Nov 2023 12:16:49 +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/h5p-staticfiles-server-core/templates/deployment.yml.j2 b/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 index 3f3244b..67367be 100644 --- a/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 +++ b/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 @@ -78,3 +78,36 @@ spec: requests: cpu: {{ H5P_STATICFIILES_SERVER_CPU_REQUESTS|default("100m", true) }} memory: {{ H5P_STATICFIILES_SERVER_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: + - h5p-staticfiles-server + topologyKey: "cloud.ionos.com/nodepool-name" + - weight: 10 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: app.kubernetes.io/name + operator: In + values: + - h5p-staticfiles-server + topologyKey: "topology.kubernetes.io/zone" From e92e43b443b5ea49b4b4d3c46c744227f70b1355 Mon Sep 17 00:00:00 2001 From: mamutmk5 <3045922+mamutmk5@users.noreply.github.com> Date: Thu, 30 Nov 2023 15:51:29 +0100 Subject: [PATCH 2/4] BC-5423 - Adjusted weighting for pod Inter-pod affinity and anti-affinity --- .../h5p-staticfiles-server-core/templates/deployment.yml.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 b/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 index 67367be..6eb8d56 100644 --- a/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 +++ b/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 @@ -81,7 +81,7 @@ spec: affinity: podAffinity: preferredDuringSchedulingIgnoredDuringExecution: - - weight: 100 + - weight: 9 podAffinityTerm: labelSelector: matchExpressions: @@ -102,7 +102,7 @@ spec: values: - h5p-staticfiles-server topologyKey: "cloud.ionos.com/nodepool-name" - - weight: 10 + - weight: 20 podAffinityTerm: labelSelector: matchExpressions: From df14591716c16a9a8c030c90651b95c7a0a0bca3 Mon Sep 17 00:00:00 2001 From: mamutmk5 <3045922+mamutmk5@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:52:44 +0100 Subject: [PATCH 3/4] BC-5423 - Make pod anti affinity rule configurable and optional --- .../h5p-staticfiles-server-core/templates/deployment.yml.j2 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 b/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 index 6eb8d56..8ac0646 100644 --- a/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 +++ b/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 @@ -93,6 +93,7 @@ spec: namespaceSelector: {} podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: +{% if ANIT_AFFINITY_NODEPOOL_ENABLE is defined and ANIT_AFFINITY_NODEPOOL_ENABLE|bool %} - weight: 10 podAffinityTerm: labelSelector: @@ -101,7 +102,8 @@ spec: operator: In values: - h5p-staticfiles-server - topologyKey: "cloud.ionos.com/nodepool-name" + topologyKey: {{ ANIT_AFFINITY_NODEPOOL_TOPOLOGY_KEY }} +{% endif %} - weight: 20 podAffinityTerm: labelSelector: From 3c16b2c75a34a4de440deb279b8d43cf9b9cb97a Mon Sep 17 00:00:00 2001 From: mamutmk5 <3045922+mamutmk5@users.noreply.github.com> Date: Mon, 4 Dec 2023 12:44:27 +0100 Subject: [PATCH 4/4] BC-5423 - make affinity rules optional --- .../h5p-staticfiles-server-core/templates/deployment.yml.j2 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 b/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 index 8ac0646..5607ccb 100644 --- a/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 +++ b/ansible/roles/h5p-staticfiles-server-core/templates/deployment.yml.j2 @@ -78,6 +78,7 @@ spec: requests: cpu: {{ H5P_STATICFIILES_SERVER_CPU_REQUESTS|default("100m", true) }} memory: {{ H5P_STATICFIILES_SERVER_MEMORY_REQUESTS|default("128Mi", true) }} +{% if AFFINITY_ENABLE is defined and AFFINITY_ENABLE|bool %} affinity: podAffinity: preferredDuringSchedulingIgnoredDuringExecution: @@ -113,3 +114,4 @@ spec: values: - h5p-staticfiles-server topologyKey: "topology.kubernetes.io/zone" +{% endif %}