Kube-State-Metrics (KSM) Emission
Since the Kubecost 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 and implemented in the cost-model, which are also the metrics being replicated:
Disabling the KSM deployment is not recommended, and will require higher up-time on the Kubecost cost-model to ensure accuracy of Kubecost data.
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 the accuracy of these metrics. Part of reaching this long-term goal requires the deployment of a pod responsible for all Kubecost metric emissions separate from the cost-model to ensure reliability and high uptime.
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