node亲和性
NodeAffinity 规则设置的注意事项
如果同时定义了nodeSelector和nodeAffinity,那么必须另个条件都得到满足。pod才能最终运行在指定的node上
如果nodeAffinity指定了多个nodeSelectorTerms,那么其中一个能匹配成功即可。
如果在nodeSelectorTerms中有多个matchExpressions,则一个节点必须满足所有matchExpressions才能运行该pod.
apiVersion: v1
kind: Pod
metadata:
name: with-node-affinity
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: beta.kubernetes.io/arch
operator: In
values:
- amd64
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: disk-type
operator: In
values:
- ssd
containers:
- name: with-node-affinity
image: gcr.io/google_containers/pause:2.0
NodeAffinity语法支持的操作符包括 In、 NotIn、 Exists、 DoesNotExist、 Gt、 Lt
NotIn和DoesNotExist 可以实现排斥的功能。