Kubernetes 亲和性调度
NodeSelector(指定运行node)
1、给node打上label
kubectl label nodes cn-hongkong.i-j6c5pm0b59y9kaos565o apptype=monitoring
2、查看结果
kubectl get nodes --show-labels
3、应用配置该标签
nodeSelector: apptype: monitoring
4、删除label
kubectl label nodes cn-hongkong.i-j6c5pm0b59y9kaos565o apptype-
NodeAffinity
例:控制pod不能在某些Node上运行,在pod的spec上添加affinity参数
affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: # 硬策略 nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: NotIn values: - node01 - node02 - node03
operator参数:
- In:label 的值在某个列表中
- NotIn:label 的值不在某个列表中
- Gt:label 的值大于某个值
- Lt:label 的值小于某个值
- Exists:某个 label 存在
- DoesNotExist:某个 label 不存在
调度pod到test环境,并每个node只能运行一个pod,提供业务可用性。
spec: nodeSelector: env: test affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: app operator: In values: - consumer-demo topologyKey: "kubernetes.io/hostname"
参考:https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
如对您有帮助,支持下呗!
微信
![](https://files.cnblogs.com/files/Dev0ps/WeChat.gif)
支付宝
![](https://files.cnblogs.com/files/Dev0ps/Alipay.gif)