简体   繁体   English

Kubernetes 缩小特定的 pod

[英]Kubernetes scale down specific pods

I have a set of Pods running commands that can take up to a couple seconds.我有一组运行命令的 Pod,可能需要几秒钟的时间。 There is a process that keeps track of open request & which Pod the request is running on.有一个进程可以跟踪打开的请求以及请求正在运行的 Pod。 I'd like the use that information when scaling down pods - either by specifying which pods to try to leave up, or specifying which pods to shut down.我希望在缩小 pod 时使用该信息 - 通过指定要尝试离开的 pod,或指定要关闭的 pod。 Is it possible to specify this type of information when changing the # of replicas, eg I want X replicas, try not to kill my long running tasks on pods A, B, C?是否可以在更改副本数量时指定此类信息,例如,我想要 X 个副本,尽量不要终止我在 pod A、B、C 上长时间运行的任务?

This isn't currently possible.这目前是不可能的。 When you scale down the number of replicas, the system will choose one to remove;当你缩减副本数量时,系统会选择一个删除; there isn't a way to "hint" at which one you'd like it to remove.没有办法“提示”您希望删除哪个。

One thing you can do is you can change the labels on running pods which can affect their membership in the replication controller.您可以做的一件事是更改正在运行的 pod 上的标签,这可能会影响它们在复制控制器中的成员资格。 This can be used to quarantine pods that you want to debug (so that they won't be part of a service or removed by a scaling event) but might also be possible to use for your use case.这可用于隔离您要调试的 pod(以便它们不会成为服务的一部分或被扩展事件删除),但也可能用于您的用例。

i've been looking for a solution to this myself, and i also can't find one out of the box.我自己一直在寻找解决方案,但我也找不到开箱即用的解决方案。 however, there might be a workaround (would love it if you could test and confirm)但是,可能有一种解决方法(如果您可以测试和确认,会喜欢它)

steps:脚步:
1. delete replication controller 1.删​​除复制控制器
2. delete X desired pods 2. 删除 X 个想要的 Pod
3. recreate replication controller of size X 3. 重新创建大小为 X 的复制控制器

As mention above, the workaround for this action should be something like this:如上所述,此操作的解决方法应该是这样的:

alias k=kubectl别名 k=kubectl

k delete pod <pods_name> && k scale --replicas=<current_replicas - 1> deploy/<name_of_deployment> k delete pod <pods_name> && k scale --replicas=<current_replicas - 1> deploy/<name_of_deployment>

Make sure you don't have an active hpa resource that is related to the deployment.确保您没有与部署相关的活动 hpa 资源。

You can annotation specific pod with controller.kubernetes.io/pod-deletion-cost: -999 and enable PodDeletionCost featuregate.您可以使用controller.kubernetes.io/pod-deletion-cost: -999注释特定的 pod,并启用PodDeletionCost门。 This feature is implement alpha in 1.21 and beta in 1.22.此功能在 1.21 中实现 alpha,在 1.22 中实现。

controller.kubernetes.io/pod-deletion-cost annotation can be set to offer a hint on the cost of deleting a pod compared to other pods belonging to the same ReplicaSet.可以设置controller.kubernetes.io/pod-deletion-cost注释以提供与属于同一 ReplicaSet 的其他 pod 相比删除 pod 的成本的提示。 Pods with lower deletion cost are deleted first.首先删除删除成本较低的 Pod。

https://github.com/kubernetes/kubernetes/pull/99163 https://github.com/kubernetes/kubernetes/pull/101080 https://github.com/kubernetes/kubernetes/pull/99163 https://github.com/kubernetes/kubernetes/pull/101080

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM