Controlling Pods with node affinity
As you can probably tell, taints and tolerations – while much more flexible than node selectors – still leave some use cases unaddressed and in general only allow a filter pattern where you can match on a specific taint using Exists
or Equals
. There may be more advanced use cases where you want more flexible methods of selecting nodes – and affinities are a feature of Kubernetes that addresses this.
There are two types of affinity:
- Node affinity
- Inter-Pod affinity
Node affinity is a similar concept to node selectors except that it allows for a much more robust set of selection characteristics. Let's look at some example YAML and then pick apart the various pieces:
pod-with-node-affinity.yaml
apiVersion: v1 kind: Pod metadata: Â Â name: affinity-test spec: Â Â affinity: Â Â Â Â nodeAffinity: Â Â Â Â Â Â requiredDuringSchedulingIgnoredDuringExecution...