Skip to content

Commit efe146b

Browse files
authored
MAJOR: kubernetes-ingress: Support PodMonitor as alternative to ServiceMonitor (#271)
Signed-off-by: Philipp Hossner <[email protected]>
1 parent 6bb553b commit efe146b

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed

kubernetes-ingress/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,22 @@ helm install my-ingress haproxytech/kubernetes-ingress \
194194
--set controller.serviceMonitor.enabled=true
195195
```
196196

197+
### Installing the PodMonitor
198+
199+
As an alternative to a `ServiceMonitor` you can use a `PodMonitor`, which targets the pods directly instead of using a service.
200+
If you're using the [Prometheus Operator](https://github.com/prometheus-operator/prometheus-operator), you can automatically install the `PodMonitor` definition in order to automate the scraping options according to your needs.
201+
202+
```console
203+
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
204+
205+
helm install prometheus prometheus-community/kube-prometheus-stack \
206+
--set prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues=false \
207+
--set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false
208+
209+
helm install my-ingress haproxytech/kubernetes-ingress \
210+
--set controller.podMonitor.enabled=true
211+
```
212+
197213
### Installing with Kubernetes Event-driven Autoscaling (KEDA)
198214

199215
[KEDA](https://keda.sh/docs/2.3/concepts/scaling-deployments/) is an improved scaling solution built on top of HPA which allows autoscaling criteria based on information from any event source including Prometheus metrics collected from HAProxy native Prometheus Exporter.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
controller:
2+
strategy:
3+
type: RollingUpdate
4+
rollingUpdate:
5+
maxUnavailable: 0
6+
maxSurge: 1

kubernetes-ingress/templates/_helpers.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ Create a default fully qualified ServiceMonitor name.
145145
{{- default (include "kubernetes-ingress.fullname" .) .Values.controller.serviceMonitor.nameOverride | trunc 63 | trimSuffix "-" -}}
146146
{{- end -}}
147147
148+
{{/*
149+
Create a default fully qualified PodMonitor name.
150+
*/}}
151+
{{- define "kubernetes-ingress.podMonitorName" -}}
152+
{{- default (include "kubernetes-ingress.fullname" .) .Values.controller.podMonitor.nameOverride | trunc 63 | trimSuffix "-" -}}
153+
{{- end -}}
154+
148155
{{/*
149156
Create a FQDN for the Service metrics.
150157
*/}}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{{/*
2+
Copyright 2024 HAProxy Technologies LLC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/}}
16+
17+
{{- if and (.Capabilities.APIVersions.Has "monitoring.coreos.com/v1") .Values.controller.podMonitor.enabled }}
18+
apiVersion: monitoring.coreos.com/v1
19+
kind: PodMonitor
20+
metadata:
21+
name: {{ include "kubernetes-ingress.podMonitorName" . }}
22+
namespace: {{ include "kubernetes-ingress.namespace" . }}
23+
labels:
24+
app.kubernetes.io/name: {{ include "kubernetes-ingress.name" . }}
25+
helm.sh/chart: {{ include "kubernetes-ingress.chart" . }}
26+
app.kubernetes.io/managed-by: {{ .Release.Service }}
27+
app.kubernetes.io/instance: {{ .Release.Name }}
28+
app.kubernetes.io/version: {{ .Chart.AppVersion }}
29+
{{- if .Values.controller.podMonitor.extraLabels }}
30+
{{ toYaml .Values.controller.podMonitor.extraLabels | nindent 4 }}
31+
{{- end }}
32+
spec:
33+
podMetricsEndpoints:
34+
{{ .Values.controller.podMonitor.endpoints | toYaml | nindent 4 }}
35+
namespaceSelector:
36+
matchNames:
37+
- {{ include "kubernetes-ingress.namespace" . }}
38+
selector:
39+
matchLabels:
40+
app.kubernetes.io/name: {{ include "kubernetes-ingress.name" . }}
41+
app.kubernetes.io/instance: {{ .Release.Name }}
42+
{{- end }}

kubernetes-ingress/values.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ controller:
563563
## --set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false
564564
serviceMonitor:
565565
## Toggle the ServiceMonitor true if you have Prometheus Operator installed and configured
566+
## Should not be enabled when controller.podMonitor.enabled is true
566567
enabled: false
567568

568569
## Specify the labels to add to the ServiceMonitors to be selected for target discovery
@@ -576,6 +577,28 @@ controller:
576577
scheme: http
577578
interval: 30s
578579

580+
## PodMonitor
581+
## ref: https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/user-guides/getting-started.md
582+
## Note: requires Prometheus Operator to be able to work, for example:
583+
## helm install prometheus prometheus-community/kube-prometheus-stack \
584+
## --set prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues=false \
585+
## --set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false
586+
podMonitor:
587+
## Toggle the PodMonitor true if you have Prometheus Operator installed and configured
588+
## Should not be enabled when controller.serviceMonitor.enabled is true
589+
enabled: false
590+
591+
## Specify the labels to add to the PodMonitors to be selected for target discovery
592+
extraLabels: {}
593+
594+
## Specify the endpoints
595+
## ref: https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/design.md#podMonitor
596+
endpoints:
597+
- port: stat
598+
path: /metrics
599+
scheme: http
600+
interval: 30s
601+
579602
## Controller sync mode with Kubernetes
580603
## Note: requires Enterprise Kubernetes Ingress Controller
581604
## Possible values: 'default' or 'fetch'

0 commit comments

Comments
 (0)