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

Lak*_*arg 0 kubernetes minikube

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

NAME       REFERENCE             TARGETS        MINPODS   MAXPODS   REPLICAS   AGE
producer   Deployment/producer   <unknown>/1%   1         3         1          42m
Run Code Online (Sandbox Code Playgroud)

以下是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: {}
Run Code Online (Sandbox Code Playgroud)

我运行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
Run Code Online (Sandbox Code Playgroud)

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

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

{"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"}
Run Code Online (Sandbox Code Playgroud)

输出来自kubectl top nodes

NAME       CPU(cores)   CPU%      MEMORY(bytes)   MEMORY%   
minikube   336m         16%       1518Mi          19%    
Run Code Online (Sandbox Code Playgroud)

我尝试过设置horizontal-pod-autoscaler-use-rest-clients=falsefor kube-controller-manager,仍然面临同样的问题。

Lak*_*arg 6

问题出在我身上producer-deployment.yaml,因为我通过编写以下行将资源请求再次覆盖为空:resources: {}之后

resources:
    requests:
        cpu: 10m
Run Code Online (Sandbox Code Playgroud)

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

删除线条resources: {}形式producer-deployment.yaml解决了这个问题。