如何决定节点中要删除的pod?

问题描述 投票:0回答:1

有什么方法可以删除我想要的特定 Pod 吗?

示例:我有一个应用程序,我设置了replicaCount:8个pod,这意味着我在8个节点中有8个pod。

4节点现货实例,4节点按需实例

在一天中的特定时间,我需要按 HPA 缩减 pod。如何删除现货实例中的 4 个 pod,同时仍保留 4 个按需实例中的 pod?

尝试搜索 Kubernetes 中的所有文档,但没有找到针对此情况的任何解决方案。 Pod 删除成本、Pod 拓扑传播约束

kubernetes scale
1个回答
0
投票

根据我的理解,您询问的是基于节点类型(例如现货实例和按需实例)的选择性 Pod 删除。在 Kubernetes 中缩小规模时,您可以结合使用污点、容忍度和节点选择器或关联规则来实现这一点,

  • 标记您的节点
kubectl label node <spot-node-name> instance-type=spot
kubectl label node <on-demand-node-name> instance-type=on-demand
  • 将您的 Deployment 配置为使用节点关联性规则,以便可以在现货节点和按需节点上调度 Pod。但是,请确保在缩小规模时也允许重新安排。
     affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: instance-type
                    operator: In
                    values:
                      - spot
                      - on-demand
  • 使用污点和容忍度确保在缩小规模时首先删除点节点上的 Pod,因为它们可以容忍污点,但不是首选。
kubectl taint nodes <spot-node-name> spot-instance=true:NoSchedule
  • 然后将容忍添加到部署清单中
      tolerations:
        - key: "spot-instance"
          operator: "Exists"
          effect: "NoSchedule"
  • 将 HPA 配置为根据反映实际负载的指标进行扩展
© www.soinside.com 2019 - 2024. All rights reserved.