Skip to content

Commit

Permalink
BC-5423 - Add POD affinity and anti-affinity (#28)
Browse files Browse the repository at this point in the history
To Improve the distribution of PODs to the least number of kubernetes worker nodes who is Required
but also to secure that the PODs of one Deployment are distributed over the Fault Zones and Node pools
the pod affinity and anti affinity are set.

Affernety number calculation:
Assign Number for an host = 0 - 20 X Fault Zone - 10 X Node Pool + 9 X Host
Host = 1 if on the host runs an POD from the Schulcloud-Verbund on any namespace
Host = 0 if on the host runs no POD from the Schulcloud-Verbund on any namespace
Node Pool = 1 if on a host of this node pool runs an POD from the Deployment
Node Pool = 0 if on no host of this node pool runs an POD from the Deployment
Fault Pool = 1 if on a host of this fault zone runs an POD from the Deployment
Fault Pool = 0 if on no host of this fault zone uns an POD from the Deployment
  • Loading branch information
mamutmk5 authored Dec 4, 2023
1 parent f691c70 commit 082c751
Showing 1 changed file with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ metadata:
namespace: {{ NAMESPACE }}
labels:
app: tldraw-client
app.kubernetes.io/part-of: schulcloud-verbund
app.kubernetes.io/version: {{ SCHULCLOUD_SERVER_IMAGE_TAG }}
app.kubernetes.io/name: tldraw-client
app.kubernetes.io/component: tldraw
app.kubernetes.io/managed-by: ansible
git.branch: {{ SCHULCLOUD_SERVER_BRANCH_NAME }}
git.repo: {{ SCHULCLOUD_SERVER_REPO_NAME }}
spec:
replicas: {{ TLDRAW_CLIENT_REPLICAS|default("1", true) }}
strategy:
Expand All @@ -20,7 +27,6 @@ spec:
metadata:
labels:
app: tldraw-client
annotations:
app.kubernetes.io/part-of: schulcloud-verbund
app.kubernetes.io/version: {{ SCHULCLOUD_SERVER_IMAGE_TAG }}
app.kubernetes.io/name: tldraw-client
Expand Down Expand Up @@ -59,6 +65,43 @@ spec:
requests:
cpu: {{ TLDRAW_CLIENT_CPU_REQUESTS|default("100m", true) }}
memory: {{ TLDRAW_CLIENT_MEMORY_REQUESTS|default("256Mi", true) }}
{% if AFFINITY_ENABLE is defined and AFFINITY_ENABLE|bool %}
affinity:
podAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 9
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app.kubernetes.io/part-of
operator: In
values:
- schulcloud-verbund
topologyKey: "kubernetes.io/hostname"
namespaceSelector: {}
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
{% if ANIT_AFFINITY_NODEPOOL_ENABLE is defined and ANIT_AFFINITY_NODEPOOL_ENABLE|bool %}
- weight: 10
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app.kubernetes.io/name
operator: In
values:
- tldraw-client
topologyKey: {{ ANIT_AFFINITY_NODEPOOL_TOPOLOGY_KEY }}
{% endif %}
- weight: 20
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app.kubernetes.io/name
operator: In
values:
- tldraw-client
topologyKey: "topology.kubernetes.io/zone"
{% endif %}
volumes:
- name: pid-dir
emptyDir: {}
Expand Down

0 comments on commit 082c751

Please sign in to comment.