部署基于HPA(Horizo​​ntal Pod Autoscaler)的自定义指标(http请求)?

时间:2019-04-04 15:14:44

标签: kubernetes prometheus

我正在使用基于http请求的HPA算法部署应用程序。 我遵循此link。 在“基于自定义指标的自动缩放”部分中。我用他们的应用程序成功构建了。但是当我在应用程序中部署时,出现错误:

$ kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/default/pods/*/http_requests" | jq .
Error from server (NotFound): the server could not find the metric http_requests for pods

在这一部分中,他们说“ podinfo应用程序公开了一个名为http_requests_total的自定义指标”。那么,我的应用程序如何公开这样的自定义指标? 非常感谢!

1 个答案:

答案 0 :(得分:0)

您可以找到有关此部署here的更多信息。
另一个示例如何为自定义指标构建应用程序,您可以找到herehere
在这两种情况下,都使用“ Golang Client API

  

在您的教程示例中,端口9898上有正在运行的应用程序   
tcp 0 0 ::: 9898 ::: * LISTEN 1 / podinfo

如果不确定应用程序是否正常运行,请进行以下验证:

    kubectl get deploy,pods
    -- verify if your new deployment is working properly 
    kubectl describe <your pod>
    -- in case of any issues with your application:
    kubectl logs <your pod>
    -- if the port and an endpoint are the same as in the example
    curl <your pod ip (endpoint)>:9898/metrics 
       you should notice http_requests_total metrics: htp_requests_total{status="200"} 1926 
    -- for generall issues
    kubectl get events

请分享您的发现和结果。