[英]HPA not able to fetch metrics from Prometheus in Kubernetes
I have a two node Kubernetes cluster ie one master node and two worker nodes. 我有两个节点的Kubernetes集群,即一个主节点和两个工作节点。 For monitoring purpose, I have deployed Prometheus and Grafana.
为了进行监视,我部署了Prometheus和Grafana。 Now, I want to autoscale pods based on CPU usage.
现在,我想根据CPU使用率自动缩放Pod。 But even after configuring Grafana and Prometheus, I am getting the following error ---
但是即使配置了Grafana和Prometheus,我仍然收到以下错误-
Name: php-apache
Namespace: default
Labels: <none>
Annotations: <none>
CreationTimestamp: Mon, 17 Jun 2019 12:33:01 +0530
Reference: Deployment/php-apache
Metrics: ( current / target )
resource cpu on pods (as a percentage of request): <unknown> / 50%
Min replicas: 1
Max replicas: 10
Deployment pods: 1 current / 0 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True SucceededGetScale the HPA controller was able to get the target's current scale
ScalingActive False FailedGetResourceMetric the HPA was unable to compute the replica count: unable to get metrics for resource cpu: unable to fetch metrics from resource metrics API: the server could not find the requested resource (get pods.metrics.k8s.io)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedGetResourceMetric 112s (x12408 over 2d4h) horizontal-pod-autoscaler unable to get metrics for resource cpu: unable to fetch metrics from resource metrics API: the server could not find the requested resource (get pods.metrics.k8s.io)
Can anybody let me know why Kubernetes is not fetching metrics from Prometheus ? 有人可以让我知道为什么Kubernetes不从Prometheus获取指标吗?
Kubernetes retrieves metrics from either the metrics.k8s.io
API (normally implemented by the metrics-server
which can be seperatly installed) or the custom.metrics.k8s.io
API (which can be any type of metric and is normally provided by third parties). Kubernetes从
metrics.k8s.io
API(通常由metrics-server
,可以单独安装)或custom.metrics.k8s.io
API(可以是任何类型的度量,通常由第三方提供)中custom.metrics.k8s.io
度量。派对)。 To use prometheus in HPA for kubernetes the Prometheus Adapter for the custom metrics API needs to be installed. 要将HPA中的Prometheus用于kubernetes,需要安装用于自定义指标API的Prometheus适配器 。
A walkthrough for the setup can be found here . 可以在此处找到设置的演练。
You don't need custom metrics to use HPA for auto-scaling pods based on their CPU usage. 您不需要自定义指标即可将HPA用于根据其CPU使用情况自动缩放Pod。
As @Blokje5 mentioned earlier, you just need to install 'kube-state-metrics'. 正如@ Blokje5前面提到的,您只需要安装'kube-state-metrics'。
The most convenient way to do it is with a dedicated helm chart ( kube-state-metrics ). 最方便的方法是使用专用头盔图( kube-state-metrics )。
Hint: use override parameters with 'helm install' to create ServiceMonitor object for 'kube-state-metrics' Pod, to allow Prometheus to discover a new target for metrics scraping, eg: 提示:将覆盖参数与'helm install'结合使用,以为'kube-state-metrics'Pod创建ServiceMonitor对象,以允许Prometheus发现用于刮取指标的新目标,例如:
helm install stable/kube-state-metrics --set prometheus.monitor.enabled=true
Remark: Pay attention to the 'serviceMonitorSelector' defined in your existing Prometheus resource object/configuration, so that it matches the ServiceMonitor definition for 'kube-state-metrics'. 备注:请注意现有Prometheus资源对象/配置中定义的“ serviceMonitorSelector”,以使其与“ kube-state-metrics”的ServiceMonitor定义匹配。 This is to make available Pods' metrics in Prometheus console.
这是为了在Prometheus控制台中提供Pods的指标。
heapster is now depracted : https://github.com/kubernetes-retired/heapster 现在不再使用heapster: https : //github.com/kubernetes-retired/heapster
To enable auto-scaling on your cluster you can use HPA(horizontal pod auto-scaler) and you can also install metrics server to check all metrics. 要在群集上启用自动扩展,您可以使用HPA(水平吊舱自动扩展器),还可以安装指标服务器来检查所有指标。
To install metrics server on kubernetes you can follow this guide also : 要在kubernetes上安装指标服务器,您还可以遵循本指南:
amazon : https://docs.aws.amazon.com/eks/latest/userguide/metrics-server.html
https://github.com/kubernetes-incubator/metrics-server
https://medium.com/@cagri.ersen/kubernetes-metrics-server-installation-d93380de008
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.