Kube-State-Metrics (KSM) Emission
Since the cost-model depends on a number of metrics emitted by kube-state-metrics, any schema changes to the expected metrics pose a long-term reliability challenge. In order to become resilient to said changes, the cost-model emits all required kube-state-metrics by default. While the result could yield double emission for some KSM metrics, it guarantees compatibility if KSM were to branch/drop specific metrics (as seen in KSM v2).
The following table shows all KSM metrics required by the cost-model, which are also the metrics being replicated:
One of the more obvious questions here is
If the metrics you are emitting cover all of the KSM requirements, could the KSM deployment be dropped?The long term plan is to drop our dependency on KSM, and while it is possible to omit the KSM deployment today, doing so would require higher up-time on the cost-model to ensure accuracy of these metrics. Part of reaching this long term goal requires the deployment of a pod responsible for all kubecost metric emission separate from the cost-model to ensure reliability and high up-time.
If an install is running KSM v1 and does not plan on updating, it is possible to disable the KSM metric replication by passing
--set .kubecostMetrics.emitKsmV1Metrics=falsewhen installing with helm, or by setting the
EMIT_KSM_V1_METRICSenvironment variable passed to the cost-model container to
If there is a deployment of KSM outside of Kubecost, Prometheus deployments that scrape Kubecost and the external KSM will have duplicate metrics for the metrics which both Kubecost and the external KSM emit. Kubecost itself is resilient to duplicate metrics, but other services or queries could be affected. There are a few 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. 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