![](/img/trans.png)
[英]get cpu utilization of virtual machines in azure using python sdk
[英]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)
在運行kubectl get hpa
時,CPU 指標是未知的。 任何幫助將非常感激。
我的 AKS kube 版本是v1.9.11
。
您需要至少安裝heapster (已棄用)或metrics-server才能使用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 限制和請求,它們只是此處的示例值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.