Kubernetes AutoScaler Not Scaling,HPA显示目标<unknown>

时间:2018-04-14 22:12:51

标签: kubernetes autoscaling

我对kubernetes很新,与Docker不同。

我一直在研究这个例子,但我坚持使用自动缩放器(它似乎没有扩展)。

我正在处理https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#step-one-run--expose-php-apache-server

中的示例

你会在底部找到构建

kubectl create -f https://k8s.io/docs/tasks/run-application/hpa-php-apache.yaml

看起来像这样

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: php-apache
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: php-apache
  minReplicas: 1
  maxReplicas: 10
  targetCPUUtilizationPercentage: 50

kubectl get hba显示

NAME         REFERENCE               TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
php-apache   Deployment/php-apache   <unknown>/50%   1         10        0          7s

<unknown>部分的线索。

然后kubectl describe hba显示

Name:                                                  php-apache
Namespace:                                             default
Labels:                                                <none>
Annotations:                                           <none>
CreationTimestamp:                                     Sat, 14 Apr 2018 23:05:05 +0100
Reference:                                             Deployment/php-apache
Metrics:                                               ( current / target )
  resource cpu on pods  (as a percentage of request):  <unknown> / 50%
Min replicas:                                          1
Max replicas:                                          10
Conditions:
  Type         Status  Reason          Message
  ----         ------  ------          -------
  AbleToScale  False   FailedGetScale  the HPA controller was unable to get the target's current scale: deployments/scale.extensions "php-apache" not found
Events:
  Type     Reason          Age                From                       Message
  ----     ------          ----               ----                       -------
  Warning  FailedGetScale  12s (x14 over 6m)  horizontal-pod-autoscaler  deployments/scale.extensions "php-apache" not found

然后我用...手动添加它。

kubectl run php-apache --image=k8s.gcr.io/hpa-example --requests=cpu=200m --expose --port=80

然后,如果我再次运行kubectl describe hpa,我会收到此错误..

Name:                                                  php-apache
Namespace:                                             default
Labels:                                                <none>
Annotations:                                           <none>
CreationTimestamp:                                     Sat, 14 Apr 2018 23:05:05 +0100
Reference:                                             Deployment/php-apache
Metrics:                                               ( current / target )
  resource cpu on pods  (as a percentage of request):  <unknown> / 50%
Min replicas:                                          1
Max replicas:                                          10
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: unable to fetch metrics from API: the server could not find the requested resource (get pods.metrics.k8s.io)
Events:
  Type     Reason                        Age                From                       Message
  ----     ------                        ----               ----                       -------
  Warning  FailedGetScale                1m (x21 over 11m)  horizontal-pod-autoscaler  deployments/scale.extensions "php-apache" not found
  Warning  FailedGetResourceMetric       8s (x2 over 38s)   horizontal-pod-autoscaler  unable to get metrics for resource cpu: unable to fetch metrics from API: the server could not find the requested resource (get pods.metrics.k8s.io)
  Warning  FailedComputeMetricsReplicas  8s (x2 over 38s)   horizontal-pod-autoscaler  failed to get cpu utilization: unable to get metrics for resource cpu: unable to fetch metrics from API: the server could not find the requested resource (get pods.metrics.k8s.io)

2 个答案:

答案 0 :(得分:3)

由于在kubernetes的更高版本(v 1.13)中不推荐使用Heapster,因此您也可以使用metrics-server公开指标,请查看以下答案以逐步设置HPA:

  

How to Enable KubeAPI server for HPA Autoscaling Metrics

答案 1 :(得分:0)

要直接回答问题,如果您已经设置了HPA资源并使用了指标服务器,并且遇到了此错误。

此错误意味着您的Pod中可能有多个容器,其中一个或两个容器都未定义资源请求:

Resources:
     requests:
       cpu: <this is missing! Add it>

检查是否所有容器都定义了资源请求。

要直接添加编辑和添加资源,请使用 kubectl edit <resource>

如果您使用掌舵,即使带有强制标志,Kubernetes可能也不允许您进行更新。

注意,如果您未设置PodDisruptionBudgets,则可能会导致停机,因此请在运行编辑之前进行设置