2.4.5. 使用 CLI 了解 pod 横向自动扩展状态条件
您可以使用设置的状态条件来判断 pod 横向自动扩展 (HPA) 是否能够缩放,以及目前是否受到某种方式的限制。
HPA 状态条件可通过 v2beta1
版的自动扩展 API 使用。
HPA 可以通过下列状态条件给予响应:
AbleToScale
条件指示 HPA 是否能够获取和更新指标,以及是否有任何与退避相关的条件阻碍了缩放。-
True
条件表示允许缩放。 -
False
条件表示因为指定原因不允许缩放。
-
ScalingActive
条件指示 HPA 是否已启用(例如,目标的副本数不为零),并且可以计算所需的指标。-
True
条件表示指标工作正常。 -
False
条件通常表示获取指标时出现问题。
-
ScalingLimited
条件表示所需的规模由 pod 横向自动扩展限定最大或最小限制。-
True
条件表示您需要提高或降低最小或最大副本数才能进行缩放。 False
条件表示允许请求的缩放。$ 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 横向自动扩展状态消息。
-
下例中是一个无法缩放的 pod:
输出示例
Conditions: Type Status Reason Message ---- ------ ------ ------- AbleToScale False FailedGetScale the HPA controller was unable to get the target's current scale: no matches for kind "ReplicationController" in group "apps" Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedGetScale 6s (x3 over 36s) horizontal-pod-autoscaler no matches for kind "ReplicationController" in group "apps"
下例中是一个无法获得缩放所需指标的 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: failed to get cpu utilization: unable to get metrics for resource cpu: no metrics returned from resource metrics API
下例中是一个请求的自动缩放低于所需下限的 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
2.4.5.1. 使用 CLI 查看 pod 横向自动扩展状态条件
您可以查看 pod 横向自动扩展 (HPA) 对 pod 设置的状态条件。
pod 横向自动扩展状态条件可通过 v2beta1
版的自动扩展 API 使用。
先决条件
要使用 pod 横向自动扩展,您的集群管理员必须已经正确配置了集群指标。您可以使用 oc describe PodMetrics <pod-name>
命令来判断是否已配置了指标。如果配置了指标,输出类似于以下示例,其中 Usage
下列出了 Cpu
和 Memory
。
$ oc describe PodMetrics openshift-kube-scheduler-ip-10-0-135-131.ec2.internal
输出示例
Name: openshift-kube-scheduler-ip-10-0-135-131.ec2.internal Namespace: openshift-kube-scheduler Labels: <none> Annotations: <none> API Version: metrics.k8s.io/v1beta1 Containers: Name: wait-for-host-port Usage: Memory: 0 Name: scheduler Usage: Cpu: 8m Memory: 45440Ki Kind: PodMetrics Metadata: Creation Timestamp: 2019-05-23T18:47:56Z Self Link: /apis/metrics.k8s.io/v1beta1/namespaces/openshift-kube-scheduler/pods/openshift-kube-scheduler-ip-10-0-135-131.ec2.internal Timestamp: 2019-05-23T18:47:56Z Window: 1m0s Events: <none>
流程
要查看 pod 上的状态条件,请使用以下命令并提供 pod 的名称:
$ oc describe hpa <pod-name>
例如:
$ oc describe hpa cm-test
这些条件会出现在输出中的 Conditions
字段里。
输出示例
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