Using inter-Pod affinity and anti-affinity
Inter-Pod affinity and anti-affinity let you dictate how Pods should run based on which other Pods already exist on a node. Since the number of Pods in a cluster is typically much larger than the number of nodes, and some Pod affinity and anti-affinity rules can be somewhat complex, this feature can put quite a load on your cluster control plane if you are running many pods on many nodes. For this reason, the Kubernetes documentation does not recommend using these features with a large number of nodes in your cluster.
Pod affinities and anti-affinities work fairly differently – let's look at each by itself before discussing how they can be combined.
Pod affinities
As with node affinities, let's dive into the YAML in order to discuss the constituent parts of a Pod affinity spec:
pod-with-pod-affinity.yaml
apiVersion: v1 kind: Pod metadata: name: not-hungry-app-affinity spec: affinity:...