Deleting external metric in Kubernetes

4/9/2020

I have setup an external metrics server in AKS (Azure Kubernetes Service). I could see the metric when querying the external metric api server.

kubectl  get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/default/queuemessages" | jq .
{
  "kind": "ExternalMetricValueList",
  "apiVersion": "external.metrics.k8s.io/v1beta1",
  "metadata": {
    "selfLink": "/apis/external.metrics.k8s.io/v1beta1/namespaces/default/queuemessages"
  },
  "items": [
    {
      "metricName": "queuemessages",
      "metricLabels": null,
      "timestamp": "2020-04-09T14:04:08Z",
      "value": "0"
    }
  ]
}

I want to know how to delete this metric from the external metrics server?

-- java_geek
azure
azure-aks
kubernetes
kubernetes-external-metrics

1 Answer

4/9/2020

It looks like you are interested in the Queue Bus metrics.

I found this issue that is still open talking about a big delay in the queue messages metric to get populated.

https://github.com/Azure/azure-k8s-metrics-adapter/issues/63

the way custom-metric adapters work, they will query metrics from external services and make them available over a custom api on the Kubernetes API-server using a APiService resource.

https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-metrics-apis

https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-metrics-not-related-to-kubernetes-objects

The adapter implements a query to the external service (Service Bus in your case) base on the spec, the get metric should never fail, so receiving a NULL could be because you don't have a valid connection OR there isn't available m metrics yet.

https://github.com/kubernetes-sigs/custom-metrics-apiserver/blob/master/docs/getting-started.md#writing-a-provider

First, there's a method for listing all metrics available at any point in time. It's used to populate the discovery information in the API, so that clients can know what metrics are available. It's not allowed to fail (it doesn't return any error), and it should return quickly, so it's suggested that you update it asynchronously in real-world code.

Could you explain why you are looking to delete the metrics ? In the end, I don't think it is possible since the adapter is there to fetch and report.

-- djsly
Source: StackOverflow