Skip to content

Commit 0b49c31

Browse files
author
Luis Vidal Ernst
committed
Added PodMonitor for kube-proxy
1 parent ad63d6b commit 0b49c31

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ If you are migrating from `release-0.7` branch or earlier please read [what chan
7070
- [Authentication problem](#authentication-problem)
7171
- [Authorization problem](#authorization-problem)
7272
- [kube-state-metrics resource usage](#kube-state-metrics-resource-usage)
73+
- [Error retrieving kube-proxy metrics](#error-retrieving-kube-proxy-metrics)
7374
- [Contributing](#contributing)
7475
- [License](#license)
7576

@@ -770,6 +771,13 @@ config. They default to:
770771
}
771772
```
772773

774+
### Error retrieving kube-proxy metrics
775+
By default, kubeadm will configure kube-proxy to listen on 127.0.0.1 for metrics. Because of this prometheus would not be able to scrape these metrics. This would have to be changed to 0.0.0.0 in one of the following two places:
776+
777+
1. Before cluster initialization, the config file passed to kubeadm init should have KubeProxyConfiguration manifest with the field metricsBindAddress set to 0.0.0.0:10249
778+
2. If the k8s cluster is already up and running, we'll have to modify the configmap kube-proxy in the namespace kube-system and set the metricsBindAddress field. After this kube-proxy daemonset would have to be restarted with
779+
`kubectl -n kube-system rollout restart daemonset kube-proxy`
780+
773781
## Contributing
774782

775783
All `.yaml` files in the `/manifests` folder are generated via

examples/kubeProxy.jsonnet

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
local kp = (import 'kube-prometheus/main.libsonnet') + {
2+
values+:: {
3+
common+: {
4+
namespace: 'monitoring',
5+
},
6+
7+
kubernetesControlPlane+: {
8+
kubeProxy: true,
9+
},
10+
},
11+
};
12+
13+
{ ['00namespace-' + name]: kp.kubePrometheus[name] for name in std.objectFields(kp.kubePrometheus) } +
14+
{ ['0prometheus-operator-' + name]: kp.prometheusOperator[name] for name in std.objectFields(kp.prometheusOperator) } +
15+
{ ['node-exporter-' + name]: kp.nodeExporter[name] for name in std.objectFields(kp.nodeExporter) } +
16+
{ ['kube-state-metrics-' + name]: kp.kubeStateMetrics[name] for name in std.objectFields(kp.kubeStateMetrics) } +
17+
{ ['alertmanager-' + name]: kp.alertmanager[name] for name in std.objectFields(kp.alertmanager) } +
18+
{ ['prometheus-' + name]: kp.prometheus[name] for name in std.objectFields(kp.prometheus) } +
19+
{ ['grafana-' + name]: kp.grafana[name] for name in std.objectFields(kp.grafana) } +
20+
{ ['kubernetes-' + name]: kp.kubernetesControlPlane[name] for name in std.objectFields(kp.kubernetesControlPlane) }

jsonnet/kube-prometheus/components/k8s-control-plane.libsonnet

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ local defaults = {
2222
hostNetworkInterfaceSelector: 'device!~"veth.+"',
2323
},
2424
},
25+
kubeProxy: false,
2526
};
2627

2728
function(params) {
@@ -234,6 +235,45 @@ function(params) {
234235
},
235236
},
236237

238+
[if (defaults + params).kubeProxy then 'podMonitorKubeProxy']: {
239+
apiVersion: 'monitoring.coreos.com/v1',
240+
kind: 'PodMonitor',
241+
metadata: {
242+
labels: {
243+
'k8s-app': 'kube-proxy',
244+
},
245+
name: 'kube-proxy',
246+
namespace: k8s._config.namespace,
247+
},
248+
spec: {
249+
jobLabel: 'k8s-app',
250+
namespaceSelector: {
251+
matchNames: [
252+
'kube-system',
253+
],
254+
},
255+
selector: {
256+
matchLabels: {
257+
'k8s-app': 'kube-proxy',
258+
},
259+
},
260+
podMetricsEndpoints: [{
261+
honorLabels: true,
262+
targetPort: 10249,
263+
relabelings: [
264+
{
265+
action: 'replace',
266+
regex: '(.*)',
267+
replacement: '$1',
268+
sourceLabels: ['__meta_kubernetes_pod_node_name'],
269+
targetLabel: 'instance',
270+
},
271+
],
272+
}],
273+
},
274+
},
275+
276+
237277
serviceMonitorCoreDNS: {
238278
apiVersion: 'monitoring.coreos.com/v1',
239279
kind: 'ServiceMonitor',

0 commit comments

Comments
 (0)