Define Custom AntiAffinity MatchLabels
Summary
Some tools didn't have a way to define a customizable AntiAffinity label. They defined only the Pod itself in AntiAffinity, but did not allow us to put some other Pod not to join in the same Node as the other for a better definition of Cluster performance.
Configuration used
gitlab:
sidekiq:
antiAffinityLabels:
matchLabels:
app: 'webservice'
gitaly:
persistence:
size: 80Gi
antiAffinityLabels:
matchLabels:
app: 'webservice'
webservice:
minReplicas: 2
maxReplicas: 4
resources:
requests:
cpu: 1
memory: 2G
limits:
cpu: 4
memory: 8G
antiAffinityLabels:
matchLabels:
app.kubernetes.io/instance: 'nexus-repository'
Current behavior
Pods with high resource utilization focusing on the same Node
Expected behavior
Being able to add AntiAffinity to Pods that use a lot of resources
Versions
- Chart: 5.10.2 stable
- Platform:
- Cloud: DigitalOcean
- Kubernetes:
1.22.8-do.1- Client:
- Server:
- Helm:
v3.5.2
Add
Looking at version 6.2.2, the "customizable" Anti Affinity is not yet added.
To add this, going to gitlab/charts/gitlab/charts/sidekiq for example, you can follow these instructions:
- Add
antiAffinityLabelsto/sideqik/values.yaml
antiAffinityLabels:
matchLabels: {}
Full values.yaml here
- Add
the .Values.antiAffinityLabels.matchLabelsvariable to/sideqik/templates/deployment.yaml
{{- if eq (default $.Values.global.antiAffinity .antiAffinity) "hard" }}
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- topologyKey: {{ default $.Values.global.affinity.podAntiAffinity.topologyKey $.Values.affinity.podAntiAffinity.topologyKey | quote }}
labelSelector:
matchLabels:
{{- toYaml $.Values.antiAffinityLabels.matchLabels | nindent 18 }}
{{- else if eq (default $.Values.global.antiAffinity .antiAffinity) "soft" }}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
podAffinityTerm:
topologyKey: {{ default $.Values.global.affinity.podAntiAffinity.topologyKey $.Values.affinity.podAntiAffinity.topologyKey | quote }}
labelSelector:
matchLabels:
{{- toYaml $.Values.antiAffinityLabels.matchLabels | nindent 18 }}
{{- end }}
Full deployment.yaml here
- Add the value to overwrite in your
gitlab-values.yaml
gitlab:
sidekiq:
antiAffinityLabels:
matchLabels:
app: 'webservice'
Looking at kubernetes we can see that it will be like this, working as expected:
Unlike how it was before, being that way fixed, not editable (test made with the same gitlab-values.yaml):

