Pod Anti-affinity for high availability
What is the motivation or use case for the change?
Multiple pods belonging to the same cluster should not be running on the same host as another pod. Manually applying a pod anti-affinity rule causes a deployment to happen and also triggers a failover if --autofail is in use.
Describe the solution you'd like
A cluster deployment should apply relevant pod anti-affinity rules by default to attempt to schedule on different hosts.
Example:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchExpressions:
- key: pg-cluster
operator: In
values:
- some-database-cluster
topologyKey: kubernetes.io/hostname
weight: 100
Agreed.. that makes sense.
this actually used to work this way by default, probably a bug, I'll take a look.
ok, definitely was a bug, this will be fixed in 3.5.1 (end of Feb), this logic is triggered if the user specifies --node-label when creating a cluster...the In and NotIn affinity rules will be created for primary and any replicas created.
3.5.1 has been released with this fix. I'm going to close this out but if anyone runs into any issues just let us know.
@jmccormick2001 Does this logic also cover PodAntiAffinity or is this limited to node labels? I would think that it's easier to let the Kubernetes scheduler handle the distribution of pods by trying to distribute pods from a certain cluster over all of the nodes.
specifying these affinity rules is useful where people want the primary to not be running on the same node as the replicas, if you don't want that behavior then not specifying a node label will let kube just schedule as normal.