Skip to content

Commit 83e0cdb

Browse files
committed
fix: allow opting-into upstream probes
Allow users to opt-into upstream probe definitions. Signed-off-by: Pranshu Srivastava <[email protected]>
1 parent a030693 commit 83e0cdb

File tree

4 files changed

+58
-27
lines changed

4 files changed

+58
-27
lines changed

jsonnet/kube-prometheus/components/kube-rbac-proxy.libsonnet

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ local defaults = {
3838
'TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305',
3939
'TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305',
4040
],
41+
// Corresponds to KRP's --ignore-paths flag.
42+
// Some components (for e.g., KSM) may utilize the flag to allow for communication with external parties in scenarios
43+
// where the originating request(s) cannot be modified to the proxy's expectations, and thus, are passed through, as
44+
// is, to certain endpoints that they target, without the proxy's intervention. The kubelet, in KSM's case, can thus
45+
// query health probe endpoints without being blocked by KRP, thus allowing for http-based probes over exec-based
46+
// ones.
47+
ignorePaths:: [],
4148
};
4249

4350

@@ -50,10 +57,11 @@ function(params) {
5057
name: krp._config.name,
5158
image: krp._config.image,
5259
args: [
53-
'--secure-listen-address=' + krp._config.secureListenAddress,
54-
'--tls-cipher-suites=' + std.join(',', krp._config.tlsCipherSuites),
55-
'--upstream=' + krp._config.upstream,
56-
],
60+
'--secure-listen-address=' + krp._config.secureListenAddress,
61+
'--tls-cipher-suites=' + std.join(',', krp._config.tlsCipherSuites),
62+
'--upstream=' + krp._config.upstream,
63+
] // Optionals.
64+
+ if std.length(krp._config.ignorePaths) > 0 then ['--ignore-paths=' + std.join(',', krp._config.ignorePaths)] else defaults.ignorePaths,
5765
resources: krp._config.resources,
5866
ports: krp._config.ports,
5967
securityContext: {

jsonnet/kube-prometheus/components/kube-state-metrics.libsonnet

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ local defaults = {
1515
},
1616

1717
kubeRbacProxyMain:: {
18+
ports: [
19+
{ name: 'http-metrics', containerPort: 8443 },
20+
],
1821
resources+: {
1922
limits+: { cpu: '40m' },
2023
requests+: { cpu: '20m' },
2124
},
2225
},
2326
kubeRbacProxySelf:: {
27+
ports: [
28+
{ name: 'telemetry', containerPort: 9443 },
29+
],
2430
resources+: {
2531
limits+: { cpu: '20m' },
2632
requests+: { cpu: '10m' },
@@ -46,6 +52,8 @@ local defaults = {
4652
runbookURLPattern: 'https://runbooks.prometheus-operator.dev/runbooks/kube-state-metrics/%s',
4753
},
4854
},
55+
// `enableProbes` allows users to opt-into upstream definitions for health probes.
56+
enableProbes:: false,
4957
};
5058

5159
function(params) (import 'github.com/kubernetes/kube-state-metrics/jsonnet/kube-state-metrics/kube-state-metrics.libsonnet') {
@@ -91,14 +99,14 @@ function(params) (import 'github.com/kubernetes/kube-state-metrics/jsonnet/kube-
9199
spec+: {
92100
ports: [
93101
{
94-
name: 'https-main',
95-
port: 8443,
96-
targetPort: 'https-main',
102+
name: defaults.kubeRbacProxyMain.ports[0].name,
103+
port: defaults.kubeRbacProxyMain.ports[0].containerPort,
104+
targetPort: defaults.kubeRbacProxyMain.ports[0].name,
97105
},
98106
{
99-
name: 'https-self',
100-
port: 9443,
101-
targetPort: 'https-self',
107+
name: defaults.kubeRbacProxySelf.ports[0].name,
108+
port: defaults.kubeRbacProxySelf.ports[0].containerPort,
109+
targetPort: defaults.kubeRbacProxySelf.ports[0].name,
102110
},
103111
],
104112
},
@@ -107,21 +115,19 @@ function(params) (import 'github.com/kubernetes/kube-state-metrics/jsonnet/kube-
107115
local kubeRbacProxyMain = krp(ksm._config.kubeRbacProxyMain {
108116
name: 'kube-rbac-proxy-main',
109117
upstream: 'http://127.0.0.1:8081/',
110-
secureListenAddress: ':8443',
111-
ports: [
112-
{ name: 'https-main', containerPort: 8443 },
113-
],
118+
secureListenAddress: ':' + std.toString(defaults.kubeRbacProxyMain.ports[0].containerPort),
114119
image: ksm._config.kubeRbacProxyImage,
120+
// When enabling probes, kube-rbac-proxy needs to always allow the /livez endpoint.
121+
ignorePaths: if ksm._config.enableProbes then ['/livez'] else super.ignorePaths,
115122
}),
116123

117124
local kubeRbacProxySelf = krp(ksm._config.kubeRbacProxySelf {
118125
name: 'kube-rbac-proxy-self',
119126
upstream: 'http://127.0.0.1:8082/',
120-
secureListenAddress: ':9443',
121-
ports: [
122-
{ name: 'https-self', containerPort: 9443 },
123-
],
127+
secureListenAddress: ':' + std.toString(defaults.kubeRbacProxySelf.ports[0].containerPort),
124128
image: ksm._config.kubeRbacProxyImage,
129+
// When enabling probes, kube-rbac-proxy needs to always allow the /readyz endpoint.
130+
ignorePaths: if ksm._config.enableProbes then ['/readyz'] else super.ignorePaths,
125131
}),
126132

127133
networkPolicy: {
@@ -161,14 +167,31 @@ function(params) (import 'github.com/kubernetes/kube-state-metrics/jsonnet/kube-
161167
spec+: {
162168
automountServiceAccountToken: true,
163169
containers: std.map(function(c) c {
164-
ports:: null,
165-
livenessProbe:: null,
166-
readinessProbe:: null,
167170
securityContext+: {
168171
runAsGroup: 65534,
169172
},
170173
args: ['--host=127.0.0.1', '--port=8081', '--telemetry-host=127.0.0.1', '--telemetry-port=8082'],
171174
resources: ksm._config.resources,
175+
} + if !ksm._config.enableProbes then {
176+
ports:: null,
177+
livenessProbe:: null,
178+
readinessProbe:: null,
179+
} else {
180+
ports: defaults.kubeRbacProxyMain.ports + defaults.kubeRbacProxySelf.ports,
181+
livenessProbe: {
182+
httpGet: {
183+
path: '/livez',
184+
port: defaults.kubeRbacProxyMain.ports[0].name,
185+
scheme: 'HTTPS',
186+
},
187+
},
188+
readinessProbe: {
189+
httpGet: {
190+
path: '/readyz',
191+
port: defaults.kubeRbacProxySelf.ports[0].name,
192+
scheme: 'HTTPS',
193+
},
194+
},
172195
}, super.containers) + [kubeRbacProxyMain, kubeRbacProxySelf],
173196
},
174197
},

manifests/kubeStateMetrics-deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ spec:
6060
name: kube-rbac-proxy-main
6161
ports:
6262
- containerPort: 8443
63-
name: https-main
63+
name: http-metrics
6464
resources:
6565
limits:
6666
cpu: 40m
@@ -87,7 +87,7 @@ spec:
8787
name: kube-rbac-proxy-self
8888
ports:
8989
- containerPort: 9443
90-
name: https-self
90+
name: telemetry
9191
resources:
9292
limits:
9393
cpu: 20m

manifests/kubeStateMetrics-service.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ metadata:
1111
spec:
1212
clusterIP: None
1313
ports:
14-
- name: https-main
14+
- name: http-metrics
1515
port: 8443
16-
targetPort: https-main
17-
- name: https-self
16+
targetPort: http-metrics
17+
- name: telemetry
1818
port: 9443
19-
targetPort: https-self
19+
targetPort: telemetry
2020
selector:
2121
app.kubernetes.io/component: exporter
2222
app.kubernetes.io/name: kube-state-metrics

0 commit comments

Comments
 (0)