From what I understand, kube-state-metrics keeps an in-memory cache of all the kubernetes events related to deployments, nodes and pods and more, and exposes them to /metrics
for Prometheus to scrape.
How long does the kube-state-metrics keep these metrics in-memory? Is it indefinitely? Or does it internally clean the cache once a while?
For most Promtheus targets, metrics are computed at scrape time. Based on kube-state-metrics' github, it looks like Kubernetes' implementation is no different. This means that the metrics are not cached, but rather calculated each time that the Prometheus server scrapes the endpoint (or each time you visit /metrics in your browser)