问题描述
我们发现我们的 Kubernetes 集群往往存在热点,其中某些节点获得的应用实例远多于其他节点。
在这种情况下,我们将部署大量 Apache Airflow 实例,并且某些节点的 Web 或调度程序组件比其他节点多 3 倍。
是否可以使用反关联性规则来强制在集群中更均匀地分布 Pod?
例如“更喜欢标签为 component=airflow-web
的 pod 最少的节点?”
如果反亲和力不起作用,我们是否还应该研究其他机制?
解决方法
尝试将其添加到 Deployment/StatefulSet .spec.template
:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: "component"
operator: In
values:
- airflow-web
topologyKey: "kubernetes.io/hostname"
,
您是否尝试过配置 kube-scheduler
?
kube-scheduler 分两步为 pod 选择一个节点:
-
Filtering
:找到可以调度 Pod 的节点集。 -
Scoring
:对剩余节点进行排名以选择最合适的 Pod 放置。
Scheduling Policies:可用于指定 kube-scheduler 运行以过滤和评分节点的 predicates 和 priorities。
kube-scheduler --policy-config-file <filename>
您的方案的优先事项之一是:
-
BalancedResourceAllocation
:支持资源使用均衡的节点。