Skip to content

Anti-affinity

Anti-affinity rules allow you to deploy your application pods on different nodes to increase the resiliency of your application.

If you are using an anti-affinity rule such as preferedDuringSchedulingIgnoredDuringExecution with labels, we recommend you to use unique labels for each deployment, to avoid the pods to deploy on all nodes.

Example: In a development environment, you use one namespace per development branch to deploy your application during development. If the label defined in the anti-affinity rule is not unique (e.g. <app_name>), Kubernetes will try to deploy pods to the pods on nodes that do not contain pods with the same label. In this case, instead of using a fixed label name, it is recommended to use a variable label name (ex: <app_name>-<branch>)

To check the configuration of your affinity/anti-affinity rules :

kubectl get deployment -A -o jsonpath='{range .items[*]}{.metadata.namespace}{":"}{"\n"}{"\t"}{.metadata.name}{":"}{"\n"}{"\t"}{"\t"}{.spec.template.spec.affinity}{"\n"}{"\n"}{end}'