26.7. 查看 Horizontal Pod Autoscaler
查看 pod 横向自动扩展的状态:
使用
oc get
命令查看 CPU 使用率和 pod 限制的信息:$ oc get hpa/hpa-resource-metrics-cpu NAME REFERENCE TARGET CURRENT MINPODS MAXPODS AGE hpa-resource-metrics-cpu DeploymentConfig/default/frontend/scale 80% 79% 1 10 8d
输出包括:
- Target。部署配置控制的所有 Pod 的目标平均 CPU 使用率。
- Current。由部署配置控制的所有 Pod 的当前 CPU 使用率。
- Minpods/Maxpods.自动缩放器可设置的最小和最大副本数。
使用
oc describe
命令获取有关 pod 横向自动扩展对象的详细信息。$ oc describe hpa/hpa-resource-metrics-cpu Name: hpa-resource-metrics-cpu Namespace: default Labels: <none> CreationTimestamp: Mon, 26 Oct 2015 21:13:47 -0400 Reference: DeploymentConfig/default/frontend/scale Target CPU utilization: 80% 1 Current CPU utilization: 79% 2 Min replicas: 1 3 Max replicas: 4 4 ReplicationController pods: 1 current / 1 desired Conditions: 5 Type Status Reason Message ---- ------ ------ ------- AbleToScale True ReadyForNewScale the last scale time was sufficiently old as to warrant a new scale ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from pods metric http_requests ScalingLimited False DesiredWithinRange the desired replica count is within the acceptable range Events:
26.7.1. 查看 Horizontal Pod Autoscaler 状态条件
您可以使用状态条件集来确定横向 pod 自动缩放器是否能够扩展以及是否以任何方式限制它。
pod 横向自动扩展状态条件可通过 v2beta1
版的自动扩展 API 使用:
kubernetesMasterConfig: ... apiServerArguments: runtime-config: - apis/autoscaling/v2beta1=true
设定了以下状态条件:
AbleToScale
指示 pod 横向自动扩展是否可以获取和更新扩展,以及任何 backoff 条件是否阻止扩展。-
True
条件表示允许缩放。 -
False
条件表示因为指定原因不允许缩放。
-
ScalingActive
指示 pod 横向自动扩展是否已启用(目标的副本计数不为零),并且可以计算所需的扩展。-
True
条件表示指标工作正常。 -
False
条件通常表示获取指标时出现问题。
-
ScalingLimited
表示不允许自动扩展,因为达到最大或最小副本数。-
True
条件表示您需要提高或降低最小或最大副本数才能进行缩放。 -
False
条件表示允许请求的缩放。
-
如果需要添加或编辑这一行,请重启 OpenShift Container Platform 服务:
# systemctl restart atomic-openshift-master-api atomic-openshift-master-controllers
要查看影响 pod 横向自动扩展的条件,请使用 oc describe hpa
。条件会出现在 status.conditions
字段中:
$ oc describe hpa cm-test
Name: cm-test
Namespace: prom
Labels: <none>
Annotations: <none>
CreationTimestamp: Fri, 16 Jun 2017 18:09:22 +0000
Reference: ReplicationController/cm-test
Metrics: ( current / target )
"http_requests" on pods: 66m / 500m
Min replicas: 1
Max replicas: 4
ReplicationController pods: 1 current / 1 desired
Conditions: 1
Type Status Reason Message
---- ------ ------ -------
AbleToScale True ReadyForNewScale the last scale time was sufficiently old as to warrant a new scale
ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from pods metric http_request
ScalingLimited False DesiredWithinRange the desired replica count is within the acceptable range
Events:
- 1
- pod 横向自动扩展状态消息。
-
AbleToScale
条件指示 HPA 是否能够获取和更新扩展,以及任何与退避相关的条件是否可防止扩展。 -
ScalingActive
条件指示 HPA 是否已启用(例如,目标副本数不为零),并且可以计算所需的扩展。False 的状态通常表示获取指标时出现问题。 -
ScalingLimited
条件表示所需的规模由 pod 横向自动扩展限定最大或最小限制。True
状态通常表示您可能需要提高或降低 pod 横向自动扩展中的最小和最大副本数限制。
-
下例中是一个无法缩放的 pod:
Conditions: Type Status Reason Message ---- ------ ------ ------- AbleToScale False FailedGetScale the HPA controller was unable to get the target's current scale: replicationcontrollers/scale.extensions "hello-hpa-cpu" not found
下例中是一个无法获得缩放所需指标的 pod:
Conditions: Type Status Reason Message ---- ------ ------ ------- AbleToScale True SucceededGetScale the HPA controller was able to get the target's current scale ScalingActive False FailedGetResourceMetric the HPA was unable to compute the replica count: unable to get metrics for resource cpu: no metrics returned from heapster
下例中是一个请求的自动缩放低于所需下限的 pod:
Conditions: Type Status Reason Message ---- ------ ------ ------- AbleToScale True ReadyForNewScale the last scale time was sufficiently old as to warrant a new scale ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from pods metric http_request ScalingLimited False DesiredWithinRange the desired replica count is within the acceptable range Events: