kubernetes HPA部署找不到目标资源

问题描述 投票:3回答:1

我正在尝试部署自己的HPA,但没有成功。在尝试部署kubernetes的官方PHP时,它按计划工作。当我尝试在Nodejs上部署自己的HPA部署文件时,它不起作用。

过程:

kubernetes official command

$ kubectl run php-apache --image=gcr.io/google_containers/hpa-example --requests=cpu=200m --expose --port=80
service "php-apache" created
deployment "php-apache" created

我的HPA部署Yaml:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: {{ .Values.name }}
  labels:
    app: {{ .Values.name }}
  namespace: {{ .Values.namespace }}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ .Values.name }}
  minReplicas: {{ .Values.spec.replicaCountMin }}
  maxReplicas: {{ .Values.spec.replicaCountMax }}
  targetCPUUtilizationPercentage: 50
  selector:
    matchLabels:
      app: {{ .Values.name }}
  template:
    metadata:
      labels:
        app: {{ .Values.name }}
        release: {{ .Release.Name }}
        heritage: {{ .Release.Service }}
    spec:
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"

结果:

PHP按计划工作

NAMESPACE           NAME        REFERENCE        TARGETS    MINPODS   MAXPODS   REPLICAS   AGE
php-apache        Deployment/php-apache        0%/50%          1         3         1          3d7h

我的发布没有

NAMESPACE           NAME        REFERENCE        TARGETS    MINPODS   MAXPODS   REPLICAS   AGE
gw-autoscale-t6   Deployment/gw-autoscale-t6   <unknown>/80%   1         3         0          11m

我的HPA Json版本

Name:                                                  gw-autoscale-t6
Namespace:                                             dev
Labels:                                                app=gw-autoscale-t6
Annotations:                                           <none>
CreationTimestamp:                                     Sun, 22 Dec 2019 22:39:44 +0200
Reference:                                             Deployment/gw-autoscale-t6
Metrics:                                               ( current / target )
  resource cpu on pods  (as a percentage of request):  <unknown> / 80%
Min replicas:                                          1
Max replicas:                                          3
Deployment pods:                                       0 current / 0 desired
Conditions:
  Type         Status  Reason          Message
  ----         ------  ------          -------
  AbleToScale  False   FailedGetScale  the HPA controller was unable to get the target's current scale: deployments/scale.apps "gw-autoscale-t6" not found
Events:
  Type     Reason          Age                 From                       Message
  ----     ------          ----                ----                       -------
  Warning  FailedGetScale  27s (x81 over 20m)  horizontal-pod-autoscaler  deployments/scale.apps "gw-autoscale-t6" not found
  • 我还尝试了许多其他类型的部署文件。

  • 已安装My Metrics-Service。

  • 我正在使用Nodejs项目的Helm安装我的部署。

我该怎么做才能解决这个问题?


回答问题:

部署结果

{
   "apiVersion": "autoscaling/v1",
   "kind": "HorizontalPodAutoscaler",
   "metadata": {
       "annotations": {
           "autoscaling.alpha.kubernetes.io/conditions": "[{\"type\":\"AbleToScale\",\"status\":\"False\",\"lastTransitionTime\":\"2019-12-22T20:39:59Z\",\"reason\":\"FailedGetScale\",\"message\":\"the HPA controller was unable to get the target's current scale: deployments/scale.apps \\\"gw-autoscale-t6\\\" not found\"}]"
       },
       "creationTimestamp": "2019-12-22T20:39:44Z",
       "labels": {
           "app": "gw-autoscale-t6"
       },
       "name": "gw-autoscale-t6",
       "namespace": "dev",
       "resourceVersion": "17299134",
       "selfLink": "/apis/autoscaling/v1/namespaces/dev/horizontalpodautoscalers/gw-autoscale-t6",
       "uid": "2f7e014c-24fb-11ea-a4d8-a28620329da6"
   },
   "spec": {
       "maxReplicas": 3,
       "minReplicas": 1,
       "scaleTargetRef": {
           "apiVersion": "apps/v1",
           "kind": "Deployment",
           "name": "gw-autoscale-t6"
       },
       "targetCPUUtilizationPercentage": 80
   },
   "status": {
       "currentReplicas": 0,
       "desiredReplicas": 0
   }
}
node.js kubernetes kubernetes-helm kubectl
1个回答
0
投票

看来部署有问题。

我试图重现这种情况,看起来您正在使用kubectl create -f hpa.yaml从文件中创建自动缩放器,以寻找群集中不存在的Deployment/gw-autoscale-t6

这就是为什么您收到以下错误:

HPA控制器无法获取目标的当前比例:Deployments / scale.apps \“找不到gw-autoscale-t6”“

为了测试,我创建了一个hpa.yaml,将其应用并查找情况:

$ date && kubectl get hpa && kubectl get deployments php-apache 

Tue 31 Dec 2019 10:59:37 AM CET

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

Error from server (NotFound): deployments.extensions "php-apache" not found

它给了我<unknown>作为TARGETS值。零为REPLICAS

如您所见,部署本身(我们正在尝试使用hpa.yaml进行扩展的部署)尚不存在。

创建部署后:

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

service/php-apache created
deployment.apps/php-apache created

我已经等待了一分钟,让HPA进行热身并计算所有内容:

$ kubectl get hpa -o yaml

apiVersion: v1
items:
- apiVersion: autoscaling/v1
  kind: HorizontalPodAutoscaler
  metadata:
    annotations:
      autoscaling.alpha.kubernetes.io/conditions: '[{"type":"AbleToScale","status":"True","lastTransitionTime":"2019-12-31T09:59:47Z","reason":"ScaleDownStabilized","message":"recent
        recommendations were higher than current one, applying the highest recent
        recommendation"},{"type":"ScalingActive","status":"True","lastTransitionTime":"2019-12-31T10:00:33Z","reason":"ValidMetricFound","message":"the
        HPA was able to successfully calculate a replica count from cpu resource utilization
        (percentage of request)"},{"type":"ScalingLimited","status":"False","lastTransitionTime":"2019-12-31T10:00:33Z","reason":"DesiredWithinRange","message":"the
        desired count is within the acceptable range"}]'
      autoscaling.alpha.kubernetes.io/current-metrics: '[{"type":"Resource","resource":{"name":"cpu","currentAverageUtilization":0,"currentAverageValue":"1m"}}]'
    creationTimestamp: "2019-12-31T09:49:16Z"
    name: php-apache
...
 spec:
    maxReplicas: 10
    minReplicas: 1
    scaleTargetRef:
      apiVersion: extensions/v1beta1
      kind: Deployment
      name: php-apache
    targetCPUUtilizationPercentage: 50
  status:
    currentCPUUtilizationPercentage: 0
    currentReplicas: 1
    desiredReplicas: 1

并再次检查:

$ date && kubectl get hpa && kubectl get deployments php-apache 

Tue 31 Dec 2019 11:01:16 AM CET
NAME         REFERENCE               TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
php-apache   Deployment/php-apache   0%/50%    1         10        1          12m

NAME         READY   UP-TO-DATE   AVAILABLE   AGE
php-apache   1/1     1            1           97s

所以现在,我可以看到REPLICA的非零值,并且TARGETS显示正确的值。

希望有帮助:)附言让我知道您是否解决了问题。

© www.soinside.com 2019 - 2024. All rights reserved.