Skip to content

Commit 995b339

Browse files
jencisodotdc
andauthored
[kube-state-metrics] Use scrapeConfig to have HA (#5470)
Signed-off-by: Juan Enciso <[email protected]> Signed-off-by: David Calvert <[email protected]> Co-authored-by: David Calvert <[email protected]>
1 parent 6a7b066 commit 995b339

File tree

4 files changed

+120
-1
lines changed

4 files changed

+120
-1
lines changed

Diff for: charts/kube-state-metrics/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ keywords:
77
- prometheus
88
- kubernetes
99
type: application
10-
version: 5.31.2
10+
version: 5.32.0
1111
# renovate: github-releases=kubernetes/kube-state-metrics
1212
appVersion: 2.15.0
1313
home: https://github.com/kubernetes/kube-state-metrics/

Diff for: charts/kube-state-metrics/templates/_helpers.tpl

+19
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,25 @@ labelValueLengthLimit: {{ . }}
104104
{{- end }}
105105
{{- end -}}
106106

107+
{{/* Sets default scrape limits for scrapeconfig */}}
108+
{{- define "scrapeconfig.scrapeLimits" -}}
109+
{{- with .sampleLimit }}
110+
sampleLimit: {{ . }}
111+
{{- end }}
112+
{{- with .targetLimit }}
113+
targetLimit: {{ . }}
114+
{{- end }}
115+
{{- with .labelLimit }}
116+
labelLimit: {{ . }}
117+
{{- end }}
118+
{{- with .labelNameLengthLimit }}
119+
labelNameLengthLimit: {{ . }}
120+
{{- end }}
121+
{{- with .labelValueLengthLimit }}
122+
labelValueLengthLimit: {{ . }}
123+
{{- end }}
124+
{{- end -}}
125+
107126
{{/*
108127
Formats imagePullSecrets. Input is (dict "Values" .Values "imagePullSecrets" .{specific imagePullSecrets})
109128
*/}}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{{- if .Values.prometheus.scrapeconfig.enabled }}
2+
apiVersion: monitoring.coreos.com/v1alpha1
3+
kind: ScrapeConfig
4+
metadata:
5+
name: {{ template "kube-state-metrics.fullname" . }}
6+
namespace: {{ template "kube-state-metrics.namespace" . }}
7+
labels:
8+
{{- include "kube-state-metrics.labels" . | indent 4 }}
9+
{{- with .Values.prometheus.scrapeconfig.additionalLabels }}
10+
{{- tpl (toYaml . | nindent 4) $ }}
11+
{{- end }}
12+
{{- with .Values.prometheus.scrapeconfig.annotations }}
13+
annotations:
14+
{{- tpl (toYaml . | nindent 4) $ }}
15+
{{- end }}
16+
spec:
17+
{{- include "scrapeconfig.scrapeLimits" .Values.prometheus.scrapeconfig | indent 2 }}
18+
staticConfigs:
19+
- targets:
20+
- {{ template "kube-state-metrics.fullname" . }}.{{ template "kube-state-metrics.namespace" . }}.svc:{{ .Values.service.port }}
21+
{{- if .Values.prometheus.scrapeconfig.staticConfigLabels}}
22+
labels:
23+
{{- with .Values.prometheus.scrapeconfig.staticConfigLabels }}
24+
{{- tpl (toYaml . | nindent 8) $ }}
25+
{{- end }}
26+
{{- end }}
27+
{{- if .Values.prometheus.scrapeconfig.jobName }}
28+
jobName: {{ .Values.prometheus.scrapeconfig.jobName }}
29+
{{- end }}
30+
{{- if .Values.prometheus.scrapeconfig.honorLabels }}
31+
honorLabels: true
32+
{{- end }}
33+
{{- if .Values.prometheus.scrapeconfig.scrapeInterval }}
34+
scrapeInterval: {{ .Values.prometheus.scrapeconfig.scrapeInterval }}
35+
{{- end }}
36+
{{- if .Values.prometheus.scrapeconfig.scrapeTimeout }}
37+
scrapeTimeout: {{ .Values.prometheus.scrapeconfig.scrapeTimeout }}
38+
{{- end }}
39+
{{- if .Values.prometheus.scrapeconfig.proxyUrl }}
40+
proxyUrl: {{ .Values.prometheus.scrapeconfig.proxyUrl }}
41+
{{- end }}
42+
{{- if .Values.prometheus.scrapeconfig.enableHttp2 }}
43+
enableHttp2: {{ .Values.prometheus.scrapeconfig.enableHttp2 }}
44+
{{- end }}
45+
{{- if .Values.prometheus.scrapeconfig.metricRelabelings }}
46+
metricRelabelings:
47+
{{- toYaml .Values.prometheus.scrapeconfig.metricRelabelings | nindent 4 }}
48+
{{- end }}
49+
{{- if .Values.prometheus.scrapeconfig.relabelings }}
50+
relabelings:
51+
{{- toYaml .Values.prometheus.scrapeconfig.relabelings | nindent 4 }}
52+
{{- end }}
53+
{{- if .Values.prometheus.scrapeconfig.scheme }}
54+
scheme: {{ .Values.prometheus.scrapeconfig.scheme }}
55+
{{- end }}
56+
{{- if .Values.prometheus.scrapeconfig.tlsConfig }}
57+
tlsConfig:
58+
{{- toYaml (.Values.prometheus.scrapeconfig.tlsConfig ) | nindent 4 }}
59+
{{- end }}
60+
{{- end }}

Diff for: charts/kube-state-metrics/values.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,46 @@ prometheus:
239239
# name: secret-name
240240
# key: key-name
241241
tlsConfig: {}
242+
## Create a scrapeConfig resource for scraping the kube-state-metrics service. Use this instead of serviceMonitor
243+
## to have more instances of kube-state-metrics safety.
244+
scrapeconfig:
245+
## To avoid duplicate metrics, first disable the serviceMonitor creation via prometheus.monitor.enabled=false
246+
enabled: false
247+
annotations: {}
248+
additionalLabels: {}
249+
jobName: kube-state-metrics
250+
## SampleLimit defines per-scrape limit on number of scraped samples that will be accepted.
251+
##
252+
sampleLimit: 0
253+
254+
## TargetLimit defines a limit on the number of scraped targets that will be accepted.
255+
##
256+
targetLimit: 0
257+
258+
## Per-scrape limit on number of labels that will be accepted for a sample. Only valid in Prometheus versions 2.27.0 and newer.
259+
##
260+
labelLimit: 0
261+
262+
## Per-scrape limit on length of labels name that will be accepted for a sample. Only valid in Prometheus versions 2.27.0 and newer.
263+
##
264+
labelNameLengthLimit: 0
265+
266+
## Per-scrape limit on length of labels value that will be accepted for a sample. Only valid in Prometheus versions 2.27.0 and newer.
267+
##
268+
labelValueLengthLimit: 0
269+
270+
## StaticConfigLabels defines the labels to be used in the Prometheus static configuration for scraping.
271+
staticConfigLabels: {}
272+
scrapeInterval: ""
273+
scrapeTimeout: ""
274+
proxyUrl: ""
275+
## Whether to enable HTTP2 for scrapeconfig
276+
enableHttp2: false
277+
honorLabels: true
278+
metricRelabelings: []
279+
relabelings: []
280+
scheme: ""
281+
tlsConfig: {}
242282

243283
## Specify if a Pod Security Policy for kube-state-metrics must be created
244284
## Ref: https://kubernetes.io/docs/concepts/policy/pod-security-policy/

0 commit comments

Comments
 (0)