首页 新闻 会员 周边

k8s 集群如何针对 pod 限制节点进行部署

0
悬赏园豆:100 [已解决问题] 解决于 2020-06-01 22:09

比如其中2个节点 k8s-node10 与 k8s-node11 ,不允许部署 blog-web 的 pods 到这2个节点 ,i-web 的 pods 只能部署到这2个节点,其他 pods 可以部署到任意节点。

k8s
dudu的主页 dudu | 高人七级 | 园豆:30943
提问于:2020-06-01 16:59
< >
分享
最佳答案
0

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]
收获园豆:90
ddrsql | 菜鸟二级 |园豆:292 | 2020-06-01 17:55

通过 node affinity 与 node anti-affinity 实现了。

  • 给 node 打标签
kubectl label nodes k8s-n10 i-web=true
kubectl label nodes k8s-n11 i-web=true
  • i-web deployment 中添加 node affinity 配置
affinity:
  nodeAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 100
        preference:
          matchExpressions:
            - key: i-web
              operator: In
              values: ["true", "yes", "1"]
  • blog-web deployment 中添加 node anti-affinity 配置
affinity:
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
        - matchExpressions:
            - key: i-web
              operator: DoesNotExist
dudu | 园豆:30943 (高人七级) | 2020-06-01 22:08
其他回答(1)
0
收获园豆:10
the boy、图样图森破 | 园豆:112 (初学一级) | 2020-06-01 18:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册