`kubectl get hpa`将目标显示为未知并且在负载增加时不会自动缩放Pod?

时间:2018-09-12 07:38:48

标签: kubernetes minikube

我创建一个部署和一个针对该部署的HPA(单节点minikube集群)。但是当我运行kubectl get hpa时,它会将目标显示为未知(以下屏幕截图)

NAME       REFERENCE             TARGETS        MINPODS   MAXPODS   REPLICAS   AGE
producer   Deployment/producer   <unknown>/1%   1         3         1          42m

以下是deployment.yaml文件:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.1.0 (36652f6)
  creationTimestamp: null
  labels:
    io.kompose.service: producer
  name: producer
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: producer
    spec:
      containers:
      - image: <image name>
        name: producer
        ports:
        - containerPort: 8090
        env:
        - name: mongoUrl
          value: mongodb://mongo:27017
        - name: mongoHost
          value: mongo
        - name: mongoPort
          value: "27017"
        resources:
          requests:
            cpu: 10m
         resources: {}
       restartPolicy: Always
status: {}

我运行kubectl autoscale deployment producer --cpu-percent=1 --min=1 --max=3命令来设置生产者部署的自动定标器。以下是kubectl describe hpa的输出:

Type     Reason                        Age                 From                       Message
  ----     ------                        ----                ----                       -------
  Warning  FailedComputeMetricsReplicas  43m (x13 over 49m)  horizontal-pod-autoscaler  failed to get cpu utilization: missing request for cpu on container producer in pod default/producer-c7dd566f6-69gbq
  Warning  FailedGetResourceMetric       4m (x91 over 49m)   horizontal-pod-autoscaler  missing request for cpu on container producer in pod default/producer-c7dd566f6-69gbq

我已经在minikube上启用了heapstermetrics-server插件,并等待hpa从最近30分钟开始运行。

minikube中来自kube-controller-manager的日志:

{"log":"I0912 10:36:40.806224       1 event.go:218] Event(v1.ObjectReference{Kind:\"HorizontalPodAutoscaler\", Namespace:\"default\", Name:\"producer\", UID:\"135d0ebc-b671-11e8-a19f-080027646864\", APIVersion:\"autoscaling/v2beta1\", ResourceVersion:\"71101\", FieldPath:\"\"}): type: 'Warning' reason: 'FailedGetResourceMetric' missing request for cpu on container producer in pod default/producer-c7dd566f6-w8zcd\n","stream":"stderr","time":"2018-09-12T10:36:40.80645916Z"}
{"log":"I0912 10:36:40.806511       1 event.go:218] Event(v1.ObjectReference{Kind:\"HorizontalPodAutoscaler\", Namespace:\"default\", Name:\"producer\", UID:\"135d0ebc-b671-11e8-a19f-080027646864\", APIVersion:\"autoscaling/v2beta1\", ResourceVersion:\"71101\", FieldPath:\"\"}): type: 'Warning' reason: 'FailedComputeMetricsReplicas' failed to get cpu utilization: missing request for cpu on container producer in pod default/producer-c7dd566f6-w8zcd\n","stream":"stderr","time":"2018-09-12T10:36:40.806564094Z"}

kubectl top nodes的输出

NAME       CPU(cores)   CPU%      MEMORY(bytes)   MEMORY%   
minikube   336m         16%       1518Mi          19%    

我尝试将horizontal-pod-autoscaler-use-rest-clients=false设置为kube-controller-manager,但仍然面临相同的问题。

1 个答案:

答案 0 :(得分:2)

问题出在我的producer-deployment.yaml上,因为我在

之后写了行:resources: {}来覆盖资源请求以再次为空
resources:
    requests:
        cpu: 10m

这使我的资源请求为空,这就是为什么heapster显示missing request for cpu on container producer的原因。

resources: {}表格中删除producer-deployment.yaml行可以解决此问题。