kubernetes - NodeSelector 不适用于多个节点池?
问题描述
TL;DR:NodeSelector 忽略来自另一个 NodePool 的节点。如何使用标签 nodeSelector 或其他技术在更多 NodePools 中分发 pod?
我有两个这样的节点池:
...
# Spot node pool
resource "azurerm_kubernetes_cluster_node_pool" "aks_staging_np_compute_spot" {
name = "computespot"
(...)
vm_size = "Standard_F8s_v2"
max_count = 2
min_count = 2
(...)
priority = "Spot"
eviction_policy = "Delete"
(...)
node_labels = {
"pool_type" = "compute"
}
# Regular node pool
resource "azurerm_kubernetes_cluster_node_pool" "aks_staging_np_compute_base" {
name = "computebase"
(...)
vm_size = "Standard_F8s_v2"
max_count = 2
min_count = 2
node_labels = {
"pool_type" = "compute"
}
两个池都部署在 AKS 中,并且所有节点都处于正常状态。请注意两点:
- 两者都有标签
pool_type: compute
- 两者的尺寸相同
Standard_F8s_v2
(我的集群中还有 20 个不同标签的其他节点并不重要。)
然后我有一个这样的部署(为了简洁省略了不相关的行):
apiVersion: apps/v1
kind: Deployment
metadata:
(...)
spec:
replicas: 4
selector:
matchLabels:
app: myapp
template:
(...)
spec:
nodeSelector:
pool_type: compute
(...)
containers:
(...)
还有一个tolerations
用于接受 Azure 现场实例的条目。它显然有效。
tolerations:
- key: "kubernetes.azure.com/scalesetpriority"
operator: "Equal"
value: "spot"
effect: "NoSchedule"
问题是应用程序仅部署在一个节点池上("computespot"
在这种情况下),并且从不接触另一个节点池( computebase
)。即使标签和单个节点的大小相同。
- 2 个 pod 在
computespot
节点上运行,每个节点一个。 - 第二个 2 pod 没有安排经典错误
0/24 nodes are available: 14 Insufficient cpu, 17 Insufficient memory, 4 node(s) didn't match node selector.
这绝对是一个谎言,因为我可以看到computebase
节点只是坐在那里完全是空的。
如何解决?
解决方案
找到了使用 pod 亲和性的解决方案。
spec:
# This didn't work:
#
# nodeSelector:
# pool_type: compute
#
# But this does:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: pool_type
operator: In
values:
- compute
我不知道原因,因为我们仍在处理一个标签。如果有人知道,请分享。
推荐阅读
- facebook - 我如何知道在 woocomerce 中我的采购订单是从哪个 facebook 活动生成的?
- bert-language-model - (Normalize () argument 2 must be str,not int)error while running BERT API
- json - Snowpipe:将 base64 编码的 JSON 加载到表中
- javascript - 如何在一页上创建多个自定义输入文件
- python - Python Regex - 在模式之间选择文本
- apache - 如何在 Apache 服务器的 .htaccess 中以 / 结尾更改所有路由(url)?
- python - 我如何知道是否使用 python-telegram-bot 删除了一条消息?
- angular - scripts.js 文件大小随着角度延迟加载而增加
- ios - 无法在 macOS Monterey 版本 12.0 Beta 中安装 Cocoapods - Xcode 13.0(13A233)
- python - 不正确的测试但不确定我的代码有什么问题?