首页 > 解决方案 > Kubernetes 复制控制器扩展查询

问题描述

我想知道在缩减请求期间复制控制器采用什么终止策略。

例如:

初始副本 = 2

创建了 2 个 Pod { Pod-1, Pod-2 }

扩展至 5

将再创建 3 个 Pod { Pod-1, Pod-2, Pod-3, Pod-4, Pod-5 }

再次缩小到 2

3 个 Pod 将被删除,我们只剩下 2 个 Pod { Pod-x, Pod-y }

现在,Replication 控制器会根据 Pod 的年龄终止并删除 Pod 吗?还是取决于 Pod 内的容器是否忙?还是随机顺序?

我对这种情况进行了几次测试,发现 Pod 是随机终止的。任何人都可以确认吗?有没有办法控制终止顺序?

提前致谢。

标签: kubernetesazure-aks

解决方案


Kubernetes复制控制器确保在任何给定时间运行指定数量的 pod“副本” 如果有太多,它会杀死一些。如果太少,它会开始更多。与用户直接创建的 Pod 不同,由 ReplicationController 维护的 Pod 在失败、删除或终止时会自动替换

在缩减过程中选择要杀死的 pod 是有逻辑的。

开发人员描述了用于选择要杀死的 pod 的工资:

// 1. Unassigned < assigned
// If only one of the pods is unassigned, the unassigned one is smaller
// 2. PodPending < PodUnknown < PodRunning
// 3. Not ready < ready
// 4. Been ready for empty time < less time < more time
// If both pods are ready, the latest ready one is smaller
// 5. Pods with containers with higher restart counts < lower restart counts
// 6. Empty creation time pods < newer pods < older pods

没有可以设置的配置选项来避免特定的 pod 被杀死。如果你想详细了解它是如何工作的——请查看源代码,好好听讲


推荐阅读