Comment on page
Kube-State-Metrics (KSM) Emission
The following table shows all KSM metrics required by and implemented in Kubecost. The below metrics and labels follow conventions of KSMv1, not KSMv2.
If interested in enabling the KSM bundled in Kubecost's Helm chart, perform the below config changes. Re-enabling KSM has the added advantage of high availability. Specifically, if the
kubecost-cost-analyzerdeployment had downtime, the
kube-state-metricsmay still be available to emit metrics for Prometheus to scrape.
While not recommended, you can disable Kubecost cost-model's emission of KSM if you are already running your own KSM.
# If you are running KSMv2, you must set the below config as well. More details below.
Disabling individual metrics is not recommended, as disabling metrics required by Kubecost to function may lead to unexpected behavior.
If your Prometheus deployment is scraping both Kubecost and an external KSM deployment outside of Kubecost, there will be duplicated KSM metrics.
Kubecost itself is resilient to duplicate metrics, but other services or queries could be affected. There are several approaches for handling this problem:
- Remove the external KSM from the cluster. If you do this, only the Kubecost-emitted metrics listed above should be available. However, This could cause other services that depend on KSM metrics to fail.
- Rewrite queries that cannot handle duplicate metrics to include a filter on
job=<external-KSM-scrape-job>or to be generally resilient to duplication using query functions like
- Run a separate Prometheus for Kubecost alone (the default installation behavior of Kubecost) and disable the scraping of Kubecost's metrics in your other Prometheus configurations.
- We support reducing some duplication from Kubecost via config. To reduce the emission of metrics that overlap with metrics provided by KSM v2 you can set the following Helm values (code ref):kubecostMetrics:emitKsmV1MetricsOnly: trueemitKsmV1Metrics: false
- The metrics that will still be emitted include:
- Node metrics (code ref)
- If you are already running KSM v2, and have set the helm value to only emit KSM v1 metrics, you can also disable the Kubecost-based KSM deployment by setting the helm value