比如其中2个节点 k8s-node10 与 k8s-node11 ,不允许部署 blog-web 的 pods 到这2个节点 ,i-web 的 pods 只能部署到这2个节点,其他 pods 可以部署到任意节点。
Affinity and anti-affinity
kubectl lable nodes k8s-node10 webtype=i-web
kubectl lable nodes k8s-node11 webtype=i-web
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: webtype
operator: In
values:
- i-web
operator:[In | NotIn | Exists | DoesNotExist | Gt | Lt]
通过 node affinity 与 node anti-affinity 实现了。
kubectl label nodes k8s-n10 i-web=true
kubectl label nodes k8s-n11 i-web=true
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
preference:
matchExpressions:
- key: i-web
operator: In
values: ["true", "yes", "1"]
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: i-web
operator: DoesNotExist