一篇带你学习Kubernetes Descheduler 使用( 四 )


apiVersion: "descheduler/v1alpha1"kind: "DeschedulerPolicy"strategies:"RemovePodsViolatingInterPodAntiAffinity":enabled: falseRemovePodsViolatingNodeTaints该策略可以确保从节点中删除违反 NoSchedule? 污点的 Pod,比如有一个名为 podA 的 Pod,通过配置容忍 key=value:NoSchedule 允许被调度到有该污点配置的节点上,如果节点的污点随后被更新或者删除了,则污点将不再被 Pods 的容忍满足,然后将被驱逐:
apiVersion: "descheduler/v1alpha1"kind: "DeschedulerPolicy"strategies:"RemovePodsViolatingNodeTaints":enabled: trueRemovePodsViolatingNodeAffinity该策略确保从节点中删除违反节点亲和性的 Pod 。比如名为 podA 的 Pod 被调度到了节点 nodeA,podA 在调度的时候满足了节点亲和性规则 requiredDuringSchedulingIgnoredDuringExecution,但是随着时间的推移,节点 nodeA 不再满足该规则了,那么如果另一个满足节点亲和性规则的节点 nodeB 可用,则 podA 将被从节点 nodeA 驱逐,如下所示的策略配置示例:
apiVersion: "descheduler/v1alpha1"kind: "DeschedulerPolicy"strategies:"RemovePodsViolatingNodeAffinity":enabled: trueparams:nodeAffinityType:- "requiredDuringSchedulingIgnoredDuringExecution" 
RemovePodsViolatingTopologySpreadConstraint该策略确保从节点驱逐违反拓扑分布约束的 Pods,具体来说,它试图驱逐将拓扑域平衡到每个约束的 ??maxSkew?? 内所需的最小 Pod 数,不过该策略需要 k8s 版本高于 1.18 才能使用 。
默认情况下,此策略仅处理硬约束,如果将参数 ??includeSoftConstraints?? 设置为 True,也将支持软约束 。
apiVersion: "descheduler/v1alpha1"kind: "DeschedulerPolicy"strategies:"RemovePodsViolatingTopologySpreadConstraint":enabled: trueparams:includeSoftConstraints: falseRemovePodsHavingTooManyRestarts该策略确保从节点中删除重启次数过多的 Pods,它的参数包括 podRestartThreshold?(这是应将 Pod 逐出的重新启动次数),以及包括InitContainers,它确定在计算中是否应考虑初始化容器的重新启动,策略配置如下所示:
apiVersion: "descheduler/v1alpha1"kind: "DeschedulerPolicy"strategies:"RemovePodsHavingTooManyRestarts":enabled: trueparams:podsHavingTooManyRestarts:podRestartThreshold: 100includingInitContainers: true Filter Pods在驱逐 Pods 的时候,有时并不需要所有 Pods 都被驱逐,descheduler 提供了两种主要的方式进行过滤:命名空间过滤和优先级过滤 。
命名空间过滤该策略可以配置是包含还是排除某些名称空间 。可以使用该策略的有:

  • PodLifeTime
  • RemovePodsHavingTooManyRestarts
  • RemovePodsViolatingNodeTaints
  • RemovePodsViolatingNodeAffinity
  • RemovePodsViolatingInterPodAntiAffinity
  • RemoveDuplicates
  • RemovePodsViolatingTopologySpreadConstraint
比如只驱逐某些命令空间下的 Pods,则可以使用 include 参数进行配置,如下所示:
apiVersion: "descheduler/v1alpha1"kind: "DeschedulerPolicy"strategies:"PodLifeTime":enabled: trueparams:podLifeTime:maxPodLifeTimeSeconds: 86400namespaces:include:- "namespace1"- "namespace2" 又或者要排除掉某些命令空间下的 Pods,则可以使用 exclude 参数配置,如下所示:
apiVersion: "descheduler/v1alpha1"kind: "DeschedulerPolicy"strategies:"PodLifeTime":enabled: trueparams:podLifeTime:maxPodLifeTimeSeconds: 86400namespaces:exclude:- "namespace1"- "namespace2" 
优先级过滤所有策略都可以配置优先级阈值,只有在该阈值以下的 Pod 才会被驱逐,我们可以通过设置 thresholdPriorityClassName?(将阈值设置为指定优先级类别的值)或 thresholdPriority?(直接设置阈值)参数来指定该阈值 。默认情况下,该阈值设置为 system-cluster-critical 这个 PriorityClass 类的值 。
比如使用 thresholdPriority:
apiVersion: "descheduler/v1alpha1"kind: "DeschedulerPolicy"strategies:"PodLifeTime":enabled: trueparams:podLifeTime:maxPodLifeTimeSeconds: 86400thresholdPriority: 10000 
或者使用 thresholdPriorityClassName 进行过滤:
apiVersion: "descheduler/v1alpha1"kind: "DeschedulerPolicy"strategies:"PodLifeTime":enabled: trueparams:podLifeTime:maxPodLifeTimeSeconds: 86400thresholdPriorityClassName: "priorityclass1"


推荐阅读