フラミナル

考え方や調べたことを書き殴ります。IT技術系記事多め

HorizontalPodAutoscaler利用時に「Warning FailedGetResourceMetric horizontal-pod-autoscaler missing request for cpu」が発生する

Kubernetes

事象

  • metrics-server導入済み
  • HPA利用時にWarning FailedGetResourceMetric horizontal-pod-autoscaler missing request for cpuというメッセージがでる
[root@master vagrant]# kubectl describe hpa nginx
Name:                                                  nginx
Namespace:                                             default
Labels:                                                app.kubernetes.io/instance=sanple-nginx
Annotations:                                           CreationTimestamp:  Tue, 14 Apr 2020 09:31:18 +0000
Reference:                                             Deployment/nginx
Metrics:                                               ( current / target )
  resource cpu on pods  (as a percentage of request):  <unknown> / 40%
Min replicas:                                          1
Max replicas:                                          5
Deployment pods:                                       1 current / 0 desired
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: did not receive metrics for any ready pods
Events:
  Type     Reason                        Age                   From                       Message
  ----     ------                        ----                  ----                       -------
  Warning  FailedComputeMetricsReplicas  15m (x12 over 18m)    horizontal-pod-autoscaler  invalid metrics (1 invalid out of 1), first error is: failed to get cpu utilization: missing request for cpu
  Warning  FailedGetResourceMetric       2m50s (x61 over 18m)  horizontal-pod-autoscaler  missing request for cpu

kubectl topは見えているのでmetrics-serverは問題なさそう。

[root@master vagrant]# kubectl top pods
NAME                            CPU(cores)   MEMORY(bytes)   
guestbook-ui-85c9c5f9cb-g5sjg   1m           7Mi             
nginx                           0m           1Mi             
nginx-5ddc966547-wtzkv          0m           1Mi             
sample-kubectl                  0m           0Mi   

解決方法

対象のDeploymentのPodに対してlimitsrequestsを追加する

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80
+       resources:
+         limits:
+           cpu: "1"
+         requests:
+           cpu: "0.5"

その後対象のHPAを再作成する。

kubectl delete hpa [HPA名]
kubectl apply -f [HPAのマニュフェスト]

memory でも別のタイミングで同じことが起きた。(missing request for memory

この時の解消方法は一度問題のある Deployments と HPA を消して再度 Apply したところなおった。

参考