Azure AKS HPA 未能获得 cpu 利用率

Azure AKS HPA failed to get cpu utilization

我在 Azure 中有一个使用 AKS 的单节点 K8s 集群。我使用一个简单的命令创建了部署和服务:

kubectl run php-apache --image=pilchard/hpa-example:latest --requests=cpu=200m,memory=300M --expose --port=80

并通过命令启用 HPA: kubectl autoscale deployment php-apache --cpu-percent=10 --min=1 --max=15

运行kubectl describe hpa php-apache 后,我看到一条错误消息:

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)
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)

并且 CPU 指标在 运行 kubectl get hpa 时未知。非常感谢任何帮助。

我的 AKS kube 版本是 v1.9.11

您需要安装 heapster(Deprecated) or the metrics-server minimally to be able to use an HPA

这提供了能够自动缩放的最小 CPU 和内存指标集。查看您是否已安装的一个好方法是,如果您从 kubectl top pod:

获得此类输出
$ kubectl top pod
NAME                        CPU(cores)   MEMORY(bytes)
http-svc-xxxxxxxxxx-xxxxx   1m           7Mi
myapp-pod                   0m           53Mi
sleep-xxxxxxxxxx-xxxxx      4m           27Mi

如果您添加了 metrics-server(这是最新请求的默认设置),请执行以下操作来修复它。

kubectl edit deployment applicationName

在上面的 cmd 中,将 appliationName 替换为您的应用程序名称,如果您调用 deployment.yml deploy,则也将其替换,并在编辑模式下,在“terminationMessagePolicy”行之后添加以下内容。

              resource:
                 requests:
                   cpu: 50m
                 limits:
                   cpu: 500m

完成编辑后,按“esc”键并输入 :wq,您的更改将在几秒钟后保存

kubectl get hpa

kubectl describe hpa applicationName

你应该看不到任何错误, 请注意根据您的应用程序使用情况更改 cpu 限制和请求,它们只是此处的示例值