Kubernetes - 根据内存和 cpu 使用情况设置 Pod 复制标准
Kubernetes - Set Pod replication criteria based on memory and cpu usage
我是 Kubernetes 世界的新手。如有不妥请见谅
我了解 pod 复制是由 k8s 本身处理的。我们还可以设置 cpu 和 pods 的内存使用。但是是否可以根据内存和 cpu 使用情况更改复制标准?例如,如果我想让一个 pod 在其 memory/cpu 使用率达到 70% 时进行复制。
我们可以使用 Prometheus 等收集的指标来做到这一点吗?
您可以使用 horizontal pod autoscaler。来自文档
The Horizontal Pod Autoscaler automatically scales the number of Pods
in a replication controller, deployment, replica set or stateful set
based on observed CPU utilization (or, with custom metrics support, on
some other application-provided metrics). Note that Horizontal Pod
Autoscaling does not apply to objects that can't be scaled, for
example, DaemonSets.
The Horizontal Pod Autoscaler is implemented as a Kubernetes API
resource and a controller. The resource determines the behavior of the
controller. The controller periodically adjusts the number of replicas
in a replication controller or deployment to match the observed
average CPU utilization to the target specified by user
示例来自 doc
以下命令将创建一个 Horizontal Pod Autoscaler,维护 Pods 的 1 到 10 个副本。 HPA 将增加和减少副本数量,以维持所有 Pods 的平均 CPU 利用率为 50%。
kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
我是 Kubernetes 世界的新手。如有不妥请见谅
我了解 pod 复制是由 k8s 本身处理的。我们还可以设置 cpu 和 pods 的内存使用。但是是否可以根据内存和 cpu 使用情况更改复制标准?例如,如果我想让一个 pod 在其 memory/cpu 使用率达到 70% 时进行复制。
我们可以使用 Prometheus 等收集的指标来做到这一点吗?
您可以使用 horizontal pod autoscaler。来自文档
The Horizontal Pod Autoscaler automatically scales the number of Pods in a replication controller, deployment, replica set or stateful set based on observed CPU utilization (or, with custom metrics support, on some other application-provided metrics). Note that Horizontal Pod Autoscaling does not apply to objects that can't be scaled, for example, DaemonSets.
The Horizontal Pod Autoscaler is implemented as a Kubernetes API resource and a controller. The resource determines the behavior of the controller. The controller periodically adjusts the number of replicas in a replication controller or deployment to match the observed average CPU utilization to the target specified by user
示例来自 doc
以下命令将创建一个 Horizontal Pod Autoscaler,维护 Pods 的 1 到 10 个副本。 HPA 将增加和减少副本数量,以维持所有 Pods 的平均 CPU 利用率为 50%。
kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10