使用 Horizontal Pod Autoscaling 以及资源请求和限制
Using Horizontal Pod Autoscaling along with resource requests and limits
假设我们有以下部署:
apiVersion: apps/v1
kind: Deployment
metadata:
...
spec:
replicas: 2
template:
spec:
containers:
- image: ...
...
resources:
requests:
cpu: 100m
memory: 50Mi
limits:
cpu: 500m
memory: 300Mi
并且我们还创建了一个 HorizontalPodAutoscaler
对象,它会根据 CPU 平均利用率自动缩放 up/down pods 的数量。我知道 HPA 将根据资源 requests 计算 pods 的数量,但是如果我希望容器能够在水平扩展之前请求更多资源怎么办?
我有两个问题:
1) 在定义 HPA 时,资源 limits 是否甚至被 K8s 使用?
2) 我可以告诉 HPA 根据资源 限制 而不是请求进行扩展吗?或者作为实现这种控制的一种手段,我可以将 targetUtilization
值设置为大于 100% 吗?
不,HPA 根本不考虑限制。您可以将目标利用率指定为甚至高于 100% 的任何值。
您好,在部署中我们有资源请求和限制。根据文档 here,这些参数在 HPA 成为自动缩放器的主要角色之前起作用:
- When you create a Pod, the Kubernetes scheduler selects a node for
the Pod to run on. Each node has a maximum capacity for each of the
resource types: the amount of CPU and memory it can provide for
Pods.
- Then the kubelet starts a Container of a Pod, it passes the CPU and memory limits to the container runtime.
- If a Container exceeds its memory limit, it might be terminated. If it is restartable, the kubelet will restart it, as with any other type of runtime failure.
如果一个 Container 超出了它的内存请求,它的 Pod 很可能会在节点内存不足时被驱逐。
另一方面:
The Horizontal Pod Autoscaler is implemented as a control loop, with a period controlled by the controller manager’s (with default value of 15 seconds).
The controller manager queries the resource utilization against the metrics specified in each HorizontalPodAutoscaler definition.
注意:
请注意,如果 pod 的某些容器没有设置相关的资源请求,CPU 将不会定义 pod 的利用率,并且自动缩放器不会对该指标采取任何操作。
希望对您有所帮助
假设我们有以下部署:
apiVersion: apps/v1
kind: Deployment
metadata:
...
spec:
replicas: 2
template:
spec:
containers:
- image: ...
...
resources:
requests:
cpu: 100m
memory: 50Mi
limits:
cpu: 500m
memory: 300Mi
并且我们还创建了一个 HorizontalPodAutoscaler
对象,它会根据 CPU 平均利用率自动缩放 up/down pods 的数量。我知道 HPA 将根据资源 requests 计算 pods 的数量,但是如果我希望容器能够在水平扩展之前请求更多资源怎么办?
我有两个问题:
1) 在定义 HPA 时,资源 limits 是否甚至被 K8s 使用?
2) 我可以告诉 HPA 根据资源 限制 而不是请求进行扩展吗?或者作为实现这种控制的一种手段,我可以将 targetUtilization
值设置为大于 100% 吗?
不,HPA 根本不考虑限制。您可以将目标利用率指定为甚至高于 100% 的任何值。
您好,在部署中我们有资源请求和限制。根据文档 here,这些参数在 HPA 成为自动缩放器的主要角色之前起作用:
- When you create a Pod, the Kubernetes scheduler selects a node for the Pod to run on. Each node has a maximum capacity for each of the resource types: the amount of CPU and memory it can provide for Pods.
- Then the kubelet starts a Container of a Pod, it passes the CPU and memory limits to the container runtime.
- If a Container exceeds its memory limit, it might be terminated. If it is restartable, the kubelet will restart it, as with any other type of runtime failure.
如果一个 Container 超出了它的内存请求,它的 Pod 很可能会在节点内存不足时被驱逐。
另一方面:
The Horizontal Pod Autoscaler is implemented as a control loop, with a period controlled by the controller manager’s (with default value of 15 seconds). The controller manager queries the resource utilization against the metrics specified in each HorizontalPodAutoscaler definition.
注意: 请注意,如果 pod 的某些容器没有设置相关的资源请求,CPU 将不会定义 pod 的利用率,并且自动缩放器不会对该指标采取任何操作。
希望对您有所帮助